msvcrt: Don't validate parameters in _itoa function.

This commit is contained in:
Piotr Caban 2013-10-15 16:29:00 +02:00 committed by Alexandre Julliard
parent 26c751ea29
commit f906be9ef4
2 changed files with 23 additions and 13 deletions

View File

@ -980,10 +980,7 @@ unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int bas
return MSVCRT_strtoui64_l(nptr, endptr, base, NULL);
}
/*********************************************************************
* _ltoa_s (MSVCRT.@)
*/
int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
static int ltoa_helper(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
{
MSVCRT_ulong val;
unsigned int digit;
@ -991,14 +988,6 @@ int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
char buffer[33], *pos;
size_t len;
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
{
str[0] = '\0';
return MSVCRT_EINVAL;
}
if (value < 0 && radix == 10)
{
is_negative = TRUE;
@ -1055,6 +1044,22 @@ int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
return 0;
}
/*********************************************************************
* _ltoa_s (MSVCRT.@)
*/
int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
{
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
{
str[0] = '\0';
return MSVCRT_EINVAL;
}
return ltoa_helper(value, str, size, radix);
}
/*********************************************************************
* _ltow_s (MSVCRT.@)
*/
@ -1143,7 +1148,7 @@ int CDECL _itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
*/
char* CDECL _itoa(int value, char *str, int radix)
{
return _itoa_s(value, str, MSVCRT_SIZE_MAX, radix) ? NULL : str;
return ltoa_helper(value, str, MSVCRT_SIZE_MAX, radix) ? NULL : str;
}
/*********************************************************************

View File

@ -1882,6 +1882,11 @@ static void test__itoa_s(void)
ok(!strcmp(buffer, "-12345678"),
"Expected output buffer string to be \"-12345678\", got \"%s\"\n",
buffer);
itoa(100, buffer, 100);
ok(!strcmp(buffer, "10"),
"Expected output buffer string to be \"10\", got \"%s\"\n", buffer);
if (p_set_invalid_parameter_handler)
ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
"Cannot reset invalid parameter handler\n");