Author: akhaldi Date: Sat May 10 20:38:26 2014 New Revision: 63223
URL: http://svn.reactos.org/svn/reactos?rev=63223&view=rev Log: [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
Modified: trunk/reactos/lib/sdk/crt/include/internal/safecrt.h trunk/reactos/lib/sdk/crt/printf/_sxprintf.c trunk/reactos/lib/sdk/crt/stdio/file.c trunk/reactos/lib/sdk/crt/stdlib/senv.c trunk/reactos/lib/sdk/crt/string/itoa.c trunk/reactos/lib/sdk/crt/string/itow.c trunk/reactos/lib/sdk/crt/string/strerror.c trunk/reactos/lib/sdk/crt/string/wcs.c trunk/reactos/lib/sdk/crt/time/gmtime.c trunk/reactos/lib/sdk/crt/wine/heap.c
Modified: trunk/reactos/lib/sdk/crt/include/internal/safecrt.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/include/interna... ============================================================================== --- trunk/reactos/lib/sdk/crt/include/internal/safecrt.h [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/include/internal/safecrt.h [iso-8859-1] Sat May 10 20:38:26 2014 @@ -11,10 +11,12 @@ 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
Modified: trunk/reactos/lib/sdk/crt/printf/_sxprintf.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_sxprint... ============================================================================== --- trunk/reactos/lib/sdk/crt/printf/_sxprintf.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/printf/_sxprintf.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -104,7 +104,7 @@ 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;
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?re... ============================================================================== --- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -1553,8 +1553,7 @@
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 @@
if (!fd) { - MSVCRT_INVALID_PMT("null out fd pointer"); - *_errno() = EINVAL; + MSVCRT_INVALID_PMT("null out fd pointer", EINVAL); return EINVAL; }
Modified: trunk/reactos/lib/sdk/crt/stdlib/senv.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdlib/senv.c?r... ============================================================================== --- trunk/reactos/lib/sdk/crt/stdlib/senv.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdlib/senv.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -109,8 +109,7 @@ { 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);
Modified: trunk/reactos/lib/sdk/crt/string/itoa.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/itoa.c?r... ============================================================================== --- trunk/reactos/lib/sdk/crt/string/itoa.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/string/itoa.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -113,10 +113,7 @@ *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 @@ }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 @@ *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; }
Modified: trunk/reactos/lib/sdk/crt/string/itow.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/itow.c?r... ============================================================================== --- trunk/reactos/lib/sdk/crt/string/itow.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/string/itow.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -123,11 +123,8 @@ 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 @@ } 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 @@ 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; }
Modified: trunk/reactos/lib/sdk/crt/string/strerror.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/strerror... ============================================================================== --- trunk/reactos/lib/sdk/crt/string/strerror.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/string/strerror.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -204,8 +204,7 @@ 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)
Modified: trunk/reactos/lib/sdk/crt/string/wcs.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/wcs.c?re... ============================================================================== --- trunk/reactos/lib/sdk/crt/string/wcs.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/string/wcs.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -432,7 +432,7 @@ } 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 @@ 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; }
Modified: trunk/reactos/lib/sdk/crt/time/gmtime.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/time/gmtime.c?r... ============================================================================== --- trunk/reactos/lib/sdk/crt/time/gmtime.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/time/gmtime.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -126,15 +126,13 @@ __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 @@ __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; }
Modified: trunk/reactos/lib/sdk/crt/wine/heap.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/wine/heap.c?rev... ============================================================================== --- trunk/reactos/lib/sdk/crt/wine/heap.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/wine/heap.c [iso-8859-1] Sat May 10 20:38:26 2014 @@ -603,8 +603,7 @@ 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; }