Farid Zaripov wrote:
> The MSVC8 CRT have the following feature: all functions, working with
> sting buffers
> (i.e. strcpy, strcat, sprintf, ...) have the security-enhanced versions
> with suffix "_s"
> (i.e. strcpy_s, strcat_s, sprintf_s, ...). And if #defined macro
> _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1
> then will be defined template overloads of the such functions, i.e.:
So the templates are disabled by default, correct? And to enable them
users would have to define the macro, both during configuration as well
as while building and using the library.
>
> template <size_t size>
> char *strcpy(char (&dest)[size], const char *src)
> {
> return strcpy_s(dest, size, src);
> }
Hmm. I'm not sure this is actually allowed by the C++ standard. Not
that that's ever stopped Microsoft before.
[...]
> I've tried to compile the stdcxx library with defined
> _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1
> and _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1, but the configure
> step has failed to
> detect this functions because of the compiler cannot decide which
> function address is taken.
>
> Here the list of the that functions:
>
> <cstdio>: gets sprintf tmpnam vsprintf
> <cstdlib>: div mbstowcs wcstombs
> <cstring>: strcat strcpy strncat strncpy
> <cwchar>: mbsrtowcs swprintf vswprintf wcrtomb wcscat wcscpy wcsncat
> wcsncpy wcsrtombs
>
> The div(int, int) function failed to detect because of the presence the
> "extern C++" div(long, long) overload.
>
> I propose to make changes in headers.inc file to check this functions
> not by takig the address, but by call the functions.
>
> The proposed patch is attached, but I not sure about passing 0 as
> va_list argument while testing vsprintf() and vswprintf().
I don't think that's guaranteed to be well-formed. va_list could
be anything, including a struct with no conversion from int. But
if you can get this issue resolved and if it compiles with all
your compilers (i.e., all versions of MSVC and Intel C++ on
Windows, as well as gcc on Linux and Cygwin), I think it should
be safe to commit the change.
Martin
>
> Farid.
>
>
> ------------------------------------------------------------------------
>
> Index: headers.inc
> ===================================================================
> --- headers.inc (revision 546565)
> +++ headers.inc (working copy)
> @@ -32,9 +32,10 @@
> # stdio functions
> c90_funs="clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen \
> fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell \
> - fwrite getc getchar gets perror printf putc putchar puts remove \
> - rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam \
> - ungetc vfprintf vprintf vsprintf"
> + fwrite getc getchar gets((char*)0) perror printf putc putchar \
> + puts remove rename rewind scanf setbuf setvbuf \
> + sprintf((char*)0,0,0) sscanf tmpfile tmpnam((char*)0) ungetc \
> + vfprintf vprintf vsprintf((char*)0,0,0)"
> c99_funs="snprintf vsnprintf"
> posix_funs="fileno"
>
> @@ -42,9 +43,10 @@
>
>
> # stdlib functions
> -c90_funs="abort abs atexit atof atoi atol atoll bsearch calloc div exit free \
> - getenv labs ldiv llabs lldiv malloc mblen mbstowcs mbtowc qsort \
> - rand realloc srand strtod strtol strtoul system wcstombs wctomb"
> +c90_funs="abort abs atexit atof atoi atol atoll bsearch calloc div(0,0) \
> + exit free getenv labs ldiv llabs lldiv malloc mblen \
> + mbstowcs((wchar_t*)0,0,0) mbtowc qsort rand realloc srand strtod \
> + strtol strtoul system wcstombs((char*)0,0,0) wctomb"
> c99_funs="strtof strtold strtoll strtoull"
> posix_funs="mkstemp putenv setenv unsetenv"
>
> @@ -52,23 +54,26 @@
>
>
> # string functions
> -string="memchr((void*)0,0,0) memcmp memcpy memmove memset strcat \
> - strchr((char*)0,0) strcmp strcoll strcpy strcspn strerror strlen \
> - strncat strncmp strncpy strpbrk((char*)0,(char*)0) \
> - strrchr((char*)0,0) strspn strstr((char*)0,(char*)0) strtok strxfrm"
> +string="memchr((void*)0,0,0) memcmp memcpy memmove memset strcat((char*)0,0) \
> + strchr((char*)0,0) strcmp strcoll strcpy((char*)0,0) strcspn \
> + strerror strlen strncat((char*)0,0,0) strncmp strncpy((char*)0,0,0) \
> + strpbrk((char*)0,(char*)0) strrchr((char*)0,0) strspn \
> + strstr((char*)0,(char*)0) strtok strxfrm"
>
>
> # wchar functions
> wchar="btowc fgetwc fgetws fputwc fputws fwide fwprintf fwscanf getwc \
> - getwchar mbrlen mbrtowc mbsinit mbsrtowcs putwc putwchar swprintf \
> - swscanf ungetwc vfwprintf vswprintf vwprintf vwscanf wcrtomb wcscat \
> - wcschr((wchar_t*)0,0) wcscmp wcscoll wcscpy wcscspn wcsftime wcslen \
> - wcsncat wcsncmp wcsncpy wcspbrk((wchar_t*)0,(wchar_t*)0) \
> - wcsrchr((wchar_t*)0,0) wcsrtombs wcsspn \
> - wcsstr((wchar_t*)0,(wchar_t*)0) wcstod wcstod wcstof wcstok wcstol \
> - wcstold wcstoll wcstoul wcstoull wcsxfrm wctob \
> - wmemchr((wchar_t*)0,0,0) wmemcmp wmemcpy wmemmove wmemset wprintf \
> - wscanf"
> + getwchar mbrlen mbrtowc mbsinit mbsrtowcs((wchar_t*)0,0,0,0) putwc \
> + putwchar swprintf((wchar_t*)0,0,0) swscanf ungetwc vfwprintf \
> + vswprintf((wchar_t*)0,0,0,0) vwprintf vwscanf wcrtomb((char*)0,0,0) \
> + wcscat((wchar_t*)0,0) wcschr((wchar_t*)0,0) wcscmp wcscoll \
> + wcscpy((wchar_t*)0,0) wcscspn wcsftime wcslen \
> + wcsncat((wchar_t*)0,0,0) wcsncmp wcsncpy((wchar_t*)0,0,0) \
> + wcspbrk((wchar_t*)0,(wchar_t*)0) wcsrchr((wchar_t*)0,0) \
> + wcsrtombs((char*)0,0,0,0) wcsspn wcsstr((wchar_t*)0,(wchar_t*)0) \
> + wcstod wcstod wcstof wcstok wcstol wcstold wcstoll wcstoul wcstoull \
> + wcsxfrm wctob wmemchr((wchar_t*)0,0,0) wmemcmp wmemcpy wmemmove \
> + wmemset wprintf wscanf"
>
>
> # wctype functions
|