Windows Security-Enhanced CRT 相关函数(即_s后辍函数)并不是对老函数的直接替代,其中不仅有更严格的参数检查,还会有buffer的重置操作等,使用的时候要格外小心,一定要仔细阅读MSDN描述或者VC runtime源码 (以Visual Studio 2008为例: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\crt\src)。
下面不妨测试3个代码片段:
测试代码【C1】:
void main() {
char dst1[8];
memcpy(dst1, NULL, 0);
memcpy(NULL, NULL, 0);
}
测试代码【C2】:
void main() {
char dst1[8];
memcpy_s(dst1, 8, NULL, 0);
memcpy_s(NULL, 0, NULL, 0);
char *dst2 = (char *)malloc(0);
if (dst2) {
memcpy_s(dst2, 0, NULL, 0);
free(dst2);
}
}
测试代码【C3】:
void main() {
char dst1[8];
memcpy_s(NULL, 0, dst1, 8);
char *dst2 = (char *)malloc(0);
if (dst2) {
memcpy_s(dst2, 0, dst1, 8);
free(dst2);
}
}
这几段代码实际上什么也没有做,只是参数有变化而已,但测试中会发现【C3】会导致程序崩溃。具体原因就是因为memcpy_s进行了更严格的参数检测,可对参考memcpy_s的源码,引用自Visual Studio 2008 runtime source memcpy_s.c:
/***
* memcpy_s.c - contains memcpy_s routine
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* Purpose:
* memcpy_s() copies a source memory buffer to a destination buffer.
* Overlapping buffers are not treated specially, so propagation may occur.
*
*******************************************************************/
#include <cruntime.h>
#include <string.h>
#include <internal.h>
/***
* memcpy_s - Copy source buffer to destination buffer
*
* Purpose:
* memcpy_s() copies a source memory buffer to a destination memory buffer.
* This routine does NOT recognize overlapping buffers, and thus can lead
* to propagation.
*
* For cases where propagation must be avoided, memmove_s() must be used.
*
* Entry:
* void *dst = pointer to destination buffer
* size_t sizeInBytes = size in bytes of the destination buffer
* const void *src = pointer to source buffer
* size_t count = number of bytes to copy
*
* Exit:
* Returns 0 if everything is ok, else return the error code.
*
* Exceptions:
* Input parameters are validated. Refer to the validation section of the function.
* On error, the error code is returned and the destination buffer is zeroed.
*
*******************************************************************/
errno_t __cdecl memcpy_s(
void * dst,
size_t sizeInBytes,
const void * src,
size_t count
)
{
if (count == 0)
{
/* nothing to do */
return 0;
}
/* validation section */
_VALIDATE_RETURN_ERRCODE(dst != NULL, EINVAL);
if (src == NULL || sizeInBytes < count)
{
/* zeroes the destination buffer */
memset(dst, 0, sizeInBytes);
_VALIDATE_RETURN_ERRCODE(src != NULL, EINVAL);
_VALIDATE_RETURN_ERRCODE(sizeInBytes >= count, ERANGE);
/* useless, but prefast is confused */
return EINVAL;
}
memcpy(dst, src, count);
return 0;
}
参考阅读:
References:
Hitnspin casino spielautomaten https://wbc1.wbc.poznan.pl/
References:
Hit’n’spin casino https://faktor-info.ru/go/?url=http://neoclassical.space/wiki/HitNSpin_Casino_Test_50_Freispiele_ohne_Einzahlung
References:
Hitnspin login perevodvsem.ru
References:
Hit n spin casino bonus forum.cmsheaven.org
References:
Hitnspin casino bonus ohne einzahlung http://diendan.gamethuvn.net/proxy.php?link=https://favpress.space/item/hit-n-spin-casino-test-2026-ehrlicher-erfahrungsbericht-bonus
References:
Hit n spin casino 25 euro code https://www.webmath.ru
References:
Hit’n’spin casino erfahrungen krs-sro.ru
References:
Hitnspin casino anmeldung soundingames.dei.uc.pt
References:
Lollybet Casino DE http://share.pho.to
References:
Lollybet Casino Erfahrungen privatecams.com
References:
Lollybet Umsatzbedingungen http://images.google.com.pg/url?q=https://christianmail.tv/@elkeprieur848?page=about
References:
Lollybet Einzahlung videoregforum.ru
References:
Lollybet Online Casino http://wiki.angloscottishmigration.humanities.manchester.ac.uk/
References:
Lollybet Meinung orienteering.sport
References:
Lollybet Casino Verifizierung http://clients1.google.com.ai/url?sa=t&url=http://gogolive.biz/@latanyafedler1?page=about
References:
Lollybet Umsatzbedingungen http://maps.google.com.co/url?q=https://srsbkn.eu.org/angeleskqa365
References:
Lollybet Gutschein http://maps.google.cz
References:
Lollybet seriös http://maps.google.es/url?q=http://downarchive.org/user/lineface8/
References:
Lollybet Casino Bonusbedingungen https://kaworu.jpn.org
References:
Hit n spin casino bonus code clients1.google.ci
References:
Hitnspin casino bonuscode clients1.google.ge
References:
Hit’n’spin casino 25 euro code http://clients1.google.ms/url?q=https://telegra.ph/HitnSpin-Casino-Deutschland-Beste-Online-Casino-Spiele-und-Boni-06-07-3
References:
Hitnspin casino sicher cse.google.az
References:
Casino hitnspin forum-otzyvov.ru
References:
Hit n spin no deposit bonus cse.google.com.ly
References:
Hit’n’spin casino 25 euro bonus ohne einzahlung
http://cse.google.tt/url?sa=i&url=https://www.altamira.edu.ec/profile/munkuiesullivan10822/profile
References:
Hitnspin casino bewertung http://clients1.google.ki/url?q=https://www.haphong.edu.vn/profile/toftubzslattery60745/profile
References:
Hit’n’spin casino no deposit bonus http://image.google.com.af/url?q=https://www.divinagracia.edu.ec/profile/lindegaardemsstein92939/profile
References:
Hit n spin casino erfahrungen http://krug-shar.ru/
References:
Hitnspin gutscheincode http://maps.google.dm/url?q=https://gratisafhalen.be/author/edgepolice6/
References:
Hit n spin casino online login 2ch.io
References:
Hitnspin casino auszahlung erfahrungen maps.google.com.co
References:
Hitnspin kundensupport http://image.google.vg/url?rct=j&sa=t&url=http://madk-auto.ru/user/crushcolumn96/
References:
Payid pokies instant withdrawal root-kit.ru
References:
Payid pokies list https://www.huntsrecruitment.com/
References:
Online pokies real money payid https://gitea.micro-stack.org/stefaniewoodar
References:
Payid withdrawal pokies https://i-medconsults.com/companies/payid-casinos-australia-top-payid-pokies-sites-2026/
References:
Lollybet Freispiele http://16.pexeburay.com
References:
Lollybet Casino Bonusbedingungen secure.jugem.jp
References:
Lollybet Anmeldung https://www.gitaristam.ru/
References:
Lollybet Casino Roulette https://depts.washington.edu/
References:
Lollybet Bonus ohne Einzahlung http://www.google.co.uz
References:
Lollybet Casino Erfahrungen m.anwap.love
References:
Lollybet Casino No Deposit skin-skin31–shop5.irisccc.cafe24.com
References:
Lollybet Startguthaben http://image.google.com.ai
References:
Lollybet Casino Erfahrungen http://www.google.cv/url?q=https://g8links.com/eileensalcedo
References:
Lollybet Casino App Download images.google.com.ua
References:
Blackjack strategy trainer https://pakalljob.pk/companies/neue-casinos-ohne-oasis-2026-die-besten-anbieter/
References:
Skyvegas com https://www.tokai-job.com/employer/kontakt-instant-casino-deutschland/
References:
Valley view casino center rukorma.ru