mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 19:55:41 +00:00
[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
This commit is contained in:
parent
be359827c5
commit
8ce24812f8
10 changed files with 24 additions and 49 deletions
|
@ -11,10 +11,12 @@ void _invalid_parameter(
|
||||||
uintptr_t pReserved);
|
uintptr_t pReserved);
|
||||||
|
|
||||||
#ifndef _LIBCNT_
|
#ifndef _LIBCNT_
|
||||||
#define MSVCRT_INVALID_PMT(x) _invalid_parameter(NULL, NULL, NULL, 0, 0)
|
#define MSVCRT_INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0))
|
||||||
#define MSVCRT_CHECK_PMT(x) ((x) || (MSVCRT_INVALID_PMT(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
|
#else
|
||||||
/* disable secure crt parameter checks */
|
/* disable secure crt parameter checks */
|
||||||
#define MSVCRT_CHECK_PMT
|
#define MSVCRT_INVALID_PMT(x,err)
|
||||||
#define MSVCRT_INVALID_PMT
|
#define MSVCRT_CHECK_PMT_ERR(x,err)
|
||||||
|
#define MSVCRT_CHECK_PMT(x) (x)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -104,7 +104,7 @@ _sxprintf(
|
||||||
if (count != _TRUNCATE)
|
if (count != _TRUNCATE)
|
||||||
{
|
{
|
||||||
/* We can't, invoke invalid parameter handler */
|
/* 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 */
|
/* If we came back, set the buffer to an empty string */
|
||||||
*buffer = 0;
|
*buffer = 0;
|
||||||
|
|
|
@ -1553,8 +1553,7 @@ int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmod
|
||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
MSVCRT_INVALID_PMT("null out fd pointer");
|
MSVCRT_INVALID_PMT("null out fd pointer", EINVAL);
|
||||||
*_errno() = EINVAL;
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1672,8 +1671,7 @@ int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int
|
||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
MSVCRT_INVALID_PMT("null out fd pointer");
|
MSVCRT_INVALID_PMT("null out fd pointer", EINVAL);
|
||||||
*_errno() = EINVAL;
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,8 +109,7 @@ int _tsearchenv_s(const _TCHAR* file, const _TCHAR* env, _TCHAR *buf, size_t cou
|
||||||
{
|
{
|
||||||
if (_tcslen(curPath) + 1 > count)
|
if (_tcslen(curPath) + 1 > count)
|
||||||
{
|
{
|
||||||
MSVCRT_INVALID_PMT("buf[count] is too small");
|
MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE);
|
||||||
*_errno() = ERANGE;
|
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
_tcscpy(buf, curPath);
|
_tcscpy(buf, curPath);
|
||||||
|
|
|
@ -113,10 +113,7 @@ int CDECL _i64toa_s(__int64 value, char *str, size_t size, int radix)
|
||||||
*p++ = *pos--;
|
*p++ = *pos--;
|
||||||
|
|
||||||
str[0] = '\0';
|
str[0] = '\0';
|
||||||
MSVCRT_INVALID_PMT("str[size] is too small");
|
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
|
||||||
#ifndef _LIBCNT_
|
|
||||||
*_errno() = ERANGE;
|
|
||||||
#endif
|
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,10 +179,7 @@ int CDECL _ui64toa_s(unsigned __int64 value, char *str,
|
||||||
}while(value != 0);
|
}while(value != 0);
|
||||||
|
|
||||||
if((unsigned)(buffer-pos+65) > size) {
|
if((unsigned)(buffer-pos+65) > size) {
|
||||||
MSVCRT_INVALID_PMT("str[size] is too small");
|
MSVCRT_INVALID_PMT("str[size] is too small", EINVAL);
|
||||||
#ifndef _LIBCNT_
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
#endif
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,10 +316,7 @@ int CDECL _ltoa_s(long value, char *str, size_t size, int radix)
|
||||||
*p++ = *pos--;
|
*p++ = *pos--;
|
||||||
|
|
||||||
str[0] = '\0';
|
str[0] = '\0';
|
||||||
MSVCRT_INVALID_PMT("str[size] is too small");
|
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
|
||||||
#ifndef _LIBCNT_
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
#endif
|
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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++)
|
for (pos = buffer + 63, i = 0; i < size; i++)
|
||||||
*p++ = *pos--;
|
*p++ = *pos--;
|
||||||
|
|
||||||
MSVCRT_INVALID_PMT("str[size] is too small");
|
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
|
||||||
str[0] = '\0';
|
str[0] = '\0';
|
||||||
#ifndef _LIBCNT_
|
|
||||||
*_errno() = ERANGE;
|
|
||||||
#endif
|
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,10 +192,7 @@ _ui64tow_s( unsigned __int64 value, wchar_t *str,
|
||||||
} while (value != 0);
|
} while (value != 0);
|
||||||
|
|
||||||
if((size_t)(buffer-pos+65) > size) {
|
if((size_t)(buffer-pos+65) > size) {
|
||||||
MSVCRT_INVALID_PMT("str[size] is too small");
|
MSVCRT_INVALID_PMT("str[size] is too small", EINVAL);
|
||||||
#ifndef _LIBCNT_
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
#endif
|
|
||||||
return 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++)
|
for (pos = buffer + 31, i = 0; i < size; i++)
|
||||||
*p++ = *pos--;
|
*p++ = *pos--;
|
||||||
|
|
||||||
MSVCRT_INVALID_PMT("str[size] is too small");
|
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
|
||||||
str[0] = '\0';
|
str[0] = '\0';
|
||||||
#ifndef _LIBCNT_
|
|
||||||
*_errno() = ERANGE;
|
|
||||||
#endif
|
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 (str && *str) len += lstrlenW(str) + 2 /* ': ' */;
|
||||||
if (len > nc)
|
if (len > nc)
|
||||||
{
|
{
|
||||||
MSVCRT_INVALID_PMT("buffer[nc] is too small");
|
MSVCRT_INVALID_PMT("buffer[nc] is too small", ERANGE);
|
||||||
_set_errno(ERANGE);
|
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
if (str && *str)
|
if (str && *str)
|
||||||
|
|
|
@ -432,7 +432,7 @@ INT CDECL wcsncat_s(wchar_t *dst, size_t elem,
|
||||||
}
|
}
|
||||||
if (dststart == 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;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ INT CDECL wcsncat_s(wchar_t *dst, size_t elem,
|
||||||
dst[dststart+srclen] = '\0';
|
dst[dststart+srclen] = '\0';
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
MSVCRT_INVALID_PMT("dst[elem] is too small");
|
MSVCRT_INVALID_PMT("dst[elem] is too small", ERANGE);
|
||||||
dst[0] = '\0';
|
dst[0] = '\0';
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,15 +126,13 @@ _gmtime64_s(
|
||||||
__time64_t time = *ptime;
|
__time64_t time = *ptime;
|
||||||
if (!ptm)
|
if (!ptm)
|
||||||
{
|
{
|
||||||
_set_errno(ERROR_BAD_COMMAND);
|
MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
|
||||||
MSVCRT_INVALID_PMT("ptm == NULL");
|
|
||||||
return ERROR_BAD_COMMAND;
|
return ERROR_BAD_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ptime)
|
if (!ptime)
|
||||||
{
|
{
|
||||||
_set_errno(ERROR_BAD_COMMAND);
|
MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
|
||||||
MSVCRT_INVALID_PMT("ptime == NULL");
|
|
||||||
return ERROR_BAD_COMMAND;
|
return ERROR_BAD_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,15 +165,13 @@ _gmtime32_s(
|
||||||
__time64_t time = *ptime;
|
__time64_t time = *ptime;
|
||||||
if (!ptm)
|
if (!ptm)
|
||||||
{
|
{
|
||||||
_set_errno(ERROR_BAD_COMMAND);
|
MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
|
||||||
MSVCRT_INVALID_PMT("ptm == NULL");
|
|
||||||
return ERROR_BAD_COMMAND;
|
return ERROR_BAD_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ptime)
|
if (!ptime)
|
||||||
{
|
{
|
||||||
_set_errno(ERROR_BAD_COMMAND);
|
MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
|
||||||
MSVCRT_INVALID_PMT("ptime == NULL");
|
|
||||||
return ERROR_BAD_COMMAND;
|
return ERROR_BAD_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -603,8 +603,7 @@ int CDECL strncpy_s(char *dest, size_t numberOfElements,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MSVCRT_INVALID_PMT("dest[numberOfElements] is too small");
|
MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL);
|
||||||
dest[0] = '\0';
|
dest[0] = '\0';
|
||||||
*_errno() = EINVAL;
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue