Given that you have provided an additional parameter that cannot be inferred ( size_t destsz), which is necessary to be exact in order to benefit from the change, you are having a real problem.
10 000 strcpy() , , .
/ , , , .
( , , , ..).
, , , .
" ", .
, filename , 255 ( NUL), strcpy(filename, () strcpy_s(filename,FILENAME_MAX_SZ.
"", .
strcpy(v, strcpy_s(v,SIZE_MAX ( ) - , , script. !;)
C11 _Generic, - :
#define __STDC_WANT_LIB_EXT1__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int strcpy_s(char *dest,size_t destsz,const char *src){
if(strlen(src)>=destsz){
return 1;
}
strcpy(dest,src);
return 0;
}
char *d_strcpy(char *dest,const char *src){
#ifndef NDEBUG
fprintf(stdout,"unsafe copy of %s\n",src);
#endif
return strcpy(dest,src);
}
#define strcpy(dest,src) _Generic (dest,\
char[100] : strcpy_s(dest,sizeof dest,src),\
char*: d_strcpy(dest,src)\
)
int main(void) {
char a[100]={'A','B','\0'};
char *b=malloc(10*sizeof(char));
strcpy(a,"XXX");
strcpy(b,"XYX");
printf("%s %s\n",a,b);
free(b);
return 0;
}
, , , , " ", Clang (untested), GCC, , ! . : N1930 ( _Generic)
.