From 8ce24812f86a3bcf79487438fe796a391575f8e8 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Sat, 10 May 2014 20:38:26 +0000 Subject: [PATCH] [CRT] * Update MSVCRT_CHECK_PMT and co. * Update the use of MSVCRT_INVALID_PMT throughout our code. * Fix the return of _ltoa_s() in some case. Fixes a couple msvcrt:string tests. CORE-8080 svn path=/trunk/; revision=63223 --- reactos/lib/sdk/crt/include/internal/safecrt.h | 10 ++++++---- reactos/lib/sdk/crt/printf/_sxprintf.c | 2 +- reactos/lib/sdk/crt/stdio/file.c | 6 ++---- reactos/lib/sdk/crt/stdlib/senv.c | 3 +-- reactos/lib/sdk/crt/string/itoa.c | 15 +++------------ reactos/lib/sdk/crt/string/itow.c | 15 +++------------ reactos/lib/sdk/crt/string/strerror.c | 3 +-- reactos/lib/sdk/crt/string/wcs.c | 4 ++-- reactos/lib/sdk/crt/time/gmtime.c | 12 ++++-------- reactos/lib/sdk/crt/wine/heap.c | 3 +-- 10 files changed, 24 insertions(+), 49 deletions(-) diff --git a/reactos/lib/sdk/crt/include/internal/safecrt.h b/reactos/lib/sdk/crt/include/internal/safecrt.h index ad948fe0c92..ec5c93038a4 100644 --- a/reactos/lib/sdk/crt/include/internal/safecrt.h +++ b/reactos/lib/sdk/crt/include/internal/safecrt.h @@ -11,10 +11,12 @@ void _invalid_parameter( uintptr_t pReserved); #ifndef _LIBCNT_ -#define MSVCRT_INVALID_PMT(x) _invalid_parameter(NULL, NULL, NULL, 0, 0) -#define MSVCRT_CHECK_PMT(x) ((x) || (MSVCRT_INVALID_PMT(0),0)) +#define MSVCRT_INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0)) +#define MSVCRT_CHECK_PMT_ERR(x,err) ((x) || (MSVCRT_INVALID_PMT( 0, (err) ), 0)) +#define MSVCRT_CHECK_PMT(x) MSVCRT_CHECK_PMT_ERR((x), EINVAL) #else /* disable secure crt parameter checks */ -#define MSVCRT_CHECK_PMT -#define MSVCRT_INVALID_PMT +#define MSVCRT_INVALID_PMT(x,err) +#define MSVCRT_CHECK_PMT_ERR(x,err) +#define MSVCRT_CHECK_PMT(x) (x) #endif diff --git a/reactos/lib/sdk/crt/printf/_sxprintf.c b/reactos/lib/sdk/crt/printf/_sxprintf.c index 57d7f4ff336..46667195314 100644 --- a/reactos/lib/sdk/crt/printf/_sxprintf.c +++ b/reactos/lib/sdk/crt/printf/_sxprintf.c @@ -104,7 +104,7 @@ _sxprintf( if (count != _TRUNCATE) { /* We can't, invoke invalid parameter handler */ - MSVCRT_INVALID_PMT("Buffer is too small"); + MSVCRT_INVALID_PMT("Buffer is too small", ERANGE); /* If we came back, set the buffer to an empty string */ *buffer = 0; diff --git a/reactos/lib/sdk/crt/stdio/file.c b/reactos/lib/sdk/crt/stdio/file.c index 52e7f09f244..0159d96d7bd 100644 --- a/reactos/lib/sdk/crt/stdio/file.c +++ b/reactos/lib/sdk/crt/stdio/file.c @@ -1553,8 +1553,7 @@ int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmod if (!fd) { - MSVCRT_INVALID_PMT("null out fd pointer"); - *_errno() = EINVAL; + MSVCRT_INVALID_PMT("null out fd pointer", EINVAL); return EINVAL; } @@ -1672,8 +1671,7 @@ int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int if (!fd) { - MSVCRT_INVALID_PMT("null out fd pointer"); - *_errno() = EINVAL; + MSVCRT_INVALID_PMT("null out fd pointer", EINVAL); return EINVAL; } diff --git a/reactos/lib/sdk/crt/stdlib/senv.c b/reactos/lib/sdk/crt/stdlib/senv.c index a7a45438b2c..ea7cafd309e 100644 --- a/reactos/lib/sdk/crt/stdlib/senv.c +++ b/reactos/lib/sdk/crt/stdlib/senv.c @@ -109,8 +109,7 @@ int _tsearchenv_s(const _TCHAR* file, const _TCHAR* env, _TCHAR *buf, size_t cou { if (_tcslen(curPath) + 1 > count) { - MSVCRT_INVALID_PMT("buf[count] is too small"); - *_errno() = ERANGE; + MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE); return ERANGE; } _tcscpy(buf, curPath); diff --git a/reactos/lib/sdk/crt/string/itoa.c b/reactos/lib/sdk/crt/string/itoa.c index e2f5918c13d..0d6e0e575c2 100644 --- a/reactos/lib/sdk/crt/string/itoa.c +++ b/reactos/lib/sdk/crt/string/itoa.c @@ -113,10 +113,7 @@ int CDECL _i64toa_s(__int64 value, char *str, size_t size, int radix) *p++ = *pos--; str[0] = '\0'; - MSVCRT_INVALID_PMT("str[size] is too small"); -#ifndef _LIBCNT_ - *_errno() = ERANGE; -#endif + MSVCRT_INVALID_PMT("str[size] is too small", ERANGE); return ERANGE; } @@ -182,10 +179,7 @@ int CDECL _ui64toa_s(unsigned __int64 value, char *str, }while(value != 0); if((unsigned)(buffer-pos+65) > size) { - MSVCRT_INVALID_PMT("str[size] is too small"); -#ifndef _LIBCNT_ - *_errno() = EINVAL; -#endif + MSVCRT_INVALID_PMT("str[size] is too small", EINVAL); return EINVAL; } @@ -322,10 +316,7 @@ int CDECL _ltoa_s(long value, char *str, size_t size, int radix) *p++ = *pos--; str[0] = '\0'; - MSVCRT_INVALID_PMT("str[size] is too small"); -#ifndef _LIBCNT_ - *_errno() = EINVAL; -#endif + MSVCRT_INVALID_PMT("str[size] is too small", ERANGE); return ERANGE; } diff --git a/reactos/lib/sdk/crt/string/itow.c b/reactos/lib/sdk/crt/string/itow.c index c18b679665a..204bcf7e3c6 100644 --- a/reactos/lib/sdk/crt/string/itow.c +++ b/reactos/lib/sdk/crt/string/itow.c @@ -123,11 +123,8 @@ _i64tow_s(__int64 value, wchar_t *str, size_t size, int radix) for (pos = buffer + 63, i = 0; i < size; i++) *p++ = *pos--; - MSVCRT_INVALID_PMT("str[size] is too small"); + MSVCRT_INVALID_PMT("str[size] is too small", ERANGE); str[0] = '\0'; -#ifndef _LIBCNT_ - *_errno() = ERANGE; -#endif return ERANGE; } @@ -195,10 +192,7 @@ _ui64tow_s( unsigned __int64 value, wchar_t *str, } while (value != 0); if((size_t)(buffer-pos+65) > size) { - MSVCRT_INVALID_PMT("str[size] is too small"); -#ifndef _LIBCNT_ - *_errno() = EINVAL; -#endif + MSVCRT_INVALID_PMT("str[size] is too small", EINVAL); return EINVAL; } @@ -338,11 +332,8 @@ _ltow_s(long value, wchar_t *str, size_t size, int radix) for (pos = buffer + 31, i = 0; i < size; i++) *p++ = *pos--; - MSVCRT_INVALID_PMT("str[size] is too small"); + MSVCRT_INVALID_PMT("str[size] is too small", ERANGE); str[0] = '\0'; -#ifndef _LIBCNT_ - *_errno() = ERANGE; -#endif return ERANGE; } diff --git a/reactos/lib/sdk/crt/string/strerror.c b/reactos/lib/sdk/crt/string/strerror.c index 8d0eced6a8b..a583c22c7bd 100644 --- a/reactos/lib/sdk/crt/string/strerror.c +++ b/reactos/lib/sdk/crt/string/strerror.c @@ -204,8 +204,7 @@ int CDECL __wcserror_s(wchar_t* buffer, size_t nc, const wchar_t* str) if (str && *str) len += lstrlenW(str) + 2 /* ': ' */; if (len > nc) { - MSVCRT_INVALID_PMT("buffer[nc] is too small"); - _set_errno(ERANGE); + MSVCRT_INVALID_PMT("buffer[nc] is too small", ERANGE); return ERANGE; } if (str && *str) diff --git a/reactos/lib/sdk/crt/string/wcs.c b/reactos/lib/sdk/crt/string/wcs.c index 846179a0589..81adfdb5e46 100644 --- a/reactos/lib/sdk/crt/string/wcs.c +++ b/reactos/lib/sdk/crt/string/wcs.c @@ -432,7 +432,7 @@ INT CDECL wcsncat_s(wchar_t *dst, size_t elem, } if (dststart == elem) { - MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n"); + MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", EINVAL); return EINVAL; } @@ -453,7 +453,7 @@ INT CDECL wcsncat_s(wchar_t *dst, size_t elem, dst[dststart+srclen] = '\0'; return ret; } - MSVCRT_INVALID_PMT("dst[elem] is too small"); + MSVCRT_INVALID_PMT("dst[elem] is too small", ERANGE); dst[0] = '\0'; return ERANGE; } diff --git a/reactos/lib/sdk/crt/time/gmtime.c b/reactos/lib/sdk/crt/time/gmtime.c index ad4eafbe46c..314811ac586 100644 --- a/reactos/lib/sdk/crt/time/gmtime.c +++ b/reactos/lib/sdk/crt/time/gmtime.c @@ -126,15 +126,13 @@ _gmtime64_s( __time64_t time = *ptime; if (!ptm) { - _set_errno(ERROR_BAD_COMMAND); - MSVCRT_INVALID_PMT("ptm == NULL"); + MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND); return ERROR_BAD_COMMAND; } if (!ptime) { - _set_errno(ERROR_BAD_COMMAND); - MSVCRT_INVALID_PMT("ptime == NULL"); + MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND); return ERROR_BAD_COMMAND; } @@ -167,15 +165,13 @@ _gmtime32_s( __time64_t time = *ptime; if (!ptm) { - _set_errno(ERROR_BAD_COMMAND); - MSVCRT_INVALID_PMT("ptm == NULL"); + MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND); return ERROR_BAD_COMMAND; } if (!ptime) { - _set_errno(ERROR_BAD_COMMAND); - MSVCRT_INVALID_PMT("ptime == NULL"); + MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND); return ERROR_BAD_COMMAND; } diff --git a/reactos/lib/sdk/crt/wine/heap.c b/reactos/lib/sdk/crt/wine/heap.c index b72f63fe6cb..8ee2d1b433f 100644 --- a/reactos/lib/sdk/crt/wine/heap.c +++ b/reactos/lib/sdk/crt/wine/heap.c @@ -603,8 +603,7 @@ int CDECL strncpy_s(char *dest, size_t numberOfElements, return 0; } - MSVCRT_INVALID_PMT("dest[numberOfElements] is too small"); + MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL); dest[0] = '\0'; - *_errno() = EINVAL; return EINVAL; } -- 2.17.1