Commit f906be9e authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Don't validate parameters in _itoa function.

parent 26c751ea
...@@ -980,10 +980,7 @@ unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int bas ...@@ -980,10 +980,7 @@ unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int bas
return MSVCRT_strtoui64_l(nptr, endptr, base, NULL); return MSVCRT_strtoui64_l(nptr, endptr, base, NULL);
} }
/********************************************************************* static int ltoa_helper(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
* _ltoa_s (MSVCRT.@)
*/
int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
{ {
MSVCRT_ulong val; MSVCRT_ulong val;
unsigned int digit; unsigned int digit;
...@@ -991,14 +988,6 @@ int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix) ...@@ -991,14 +988,6 @@ int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
char buffer[33], *pos; char buffer[33], *pos;
size_t len; 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) if (value < 0 && radix == 10)
{ {
is_negative = TRUE; is_negative = TRUE;
...@@ -1056,6 +1045,22 @@ int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix) ...@@ -1056,6 +1045,22 @@ int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
} }
/********************************************************************* /*********************************************************************
* _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.@) * _ltow_s (MSVCRT.@)
*/ */
int CDECL _ltow_s(MSVCRT_long value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix) int CDECL _ltow_s(MSVCRT_long value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
...@@ -1143,7 +1148,7 @@ int CDECL _itoa_s(int value, char *str, MSVCRT_size_t size, int radix) ...@@ -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) 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;
} }
/********************************************************************* /*********************************************************************
......
...@@ -1882,6 +1882,11 @@ static void test__itoa_s(void) ...@@ -1882,6 +1882,11 @@ static void test__itoa_s(void)
ok(!strcmp(buffer, "-12345678"), ok(!strcmp(buffer, "-12345678"),
"Expected output buffer string to be \"-12345678\", got \"%s\"\n", "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
buffer); 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) if (p_set_invalid_parameter_handler)
ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler, ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
"Cannot reset invalid parameter handler\n"); "Cannot reset invalid parameter handler\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment