msvcrt: Don't detect overflow in atoi implementation.

This commit is contained in:
Piotr Caban 2013-06-04 15:52:10 +02:00 committed by Alexandre Julliard
parent 0210cb9385
commit f3eb64ec73
11 changed files with 71 additions and 7 deletions

View file

@ -484,6 +484,11 @@ size_t CDECL _aligned_msize(void *p, size_t alignment, size_t offset)
return _msize(*alloc_ptr)-alignment-sizeof(void*);
}
int CDECL MSVCR100_atoi(const char *str)
{
return _atoi_l(str, NULL);
}
/*********************************************************************
* DllMain (MSVCR100.@)
*/

View file

@ -1629,7 +1629,7 @@
@ cdecl -arch=arm,x86_64 atan2f(float float) msvcrt.atan2f
@ cdecl atexit(ptr) msvcrt.atexit
@ cdecl atof(str) msvcrt.atof
@ cdecl atoi(str) msvcrt.atoi
@ cdecl atoi(str) MSVCR100_atoi
@ cdecl atol(str) msvcrt.atol
@ cdecl bsearch(ptr ptr long long ptr) msvcrt.bsearch
@ cdecl bsearch_s(ptr ptr long long ptr ptr) msvcrt.bsearch_s

View file

@ -75,6 +75,7 @@ static size_t (__cdecl *p_fread_s)(void*,size_t,size_t,size_t,FILE*);
static void* (__cdecl *p__aligned_offset_malloc)(size_t, size_t, size_t);
static void (__cdecl *p__aligned_free)(void*);
static size_t (__cdecl *p__aligned_msize)(void*, size_t, size_t);
static int (__cdecl *p_atoi)(const char*);
/* make sure we use the correct errno */
#undef errno
@ -104,6 +105,7 @@ static BOOL init(void)
SET(p__aligned_offset_malloc, "_aligned_offset_malloc");
SET(p__aligned_free, "_aligned_free");
SET(p__aligned_msize, "_aligned_msize");
SET(p_atoi, "atoi");
return TRUE;
}
@ -358,6 +360,23 @@ static void test__aligned_msize(void)
p__aligned_free(mem);
}
static void test_atoi(void)
{
int r;
r = p_atoi("0");
ok(r == 0, "atoi(0) = %d\n", r);
r = p_atoi("-1");
ok(r == -1, "atoi(-1) = %d\n", r);
r = p_atoi("1");
ok(r == 1, "atoi(1) = %d\n", r);
r = p_atoi("4294967296");
ok(r == 2147483647, "atoi(4294967296) = %d\n", r);
}
START_TEST(msvcr100)
{
if (!init())
@ -367,4 +386,5 @@ START_TEST(msvcr100)
test_wmemmove_s();
test_fread_s();
test__aligned_msize();
test_atoi();
}

View file

@ -1991,7 +1991,7 @@
@ cdecl -arch=arm,x86_64 atan2f(float float) msvcrt.atan2f
@ cdecl atexit(ptr) msvcrt.atexit
@ cdecl atof(str) msvcrt.atof
@ cdecl atoi(str) msvcrt.atoi
@ cdecl atoi(str) msvcr100.atoi #don't forward to msvcrt
@ cdecl atol(str) msvcrt.atol
@ cdecl bsearch(ptr ptr long long ptr) msvcrt.bsearch
@ cdecl bsearch_s(ptr ptr long long ptr ptr) msvcrt.bsearch_s

View file

@ -688,7 +688,7 @@
@ cdecl atan2(double double) msvcrt.atan2
@ cdecl atexit(ptr) msvcrt.atexit
@ cdecl atof(str) msvcrt.atof
@ cdecl atoi(str) msvcrt.atoi
@ cdecl atoi(str) msvcr100.atoi #don't forward to msvcrt
@ cdecl atol(str) msvcrt.atol
@ cdecl bsearch(ptr ptr long long ptr) msvcrt.bsearch
@ cdecl calloc(long long) msvcrt.calloc

View file

@ -684,7 +684,7 @@
@ cdecl atan2(double double) msvcrt.atan2
@ cdecl atexit(ptr) msvcrt.atexit
@ cdecl atof(str) msvcrt.atof
@ cdecl atoi(str) msvcrt.atoi
@ cdecl atoi(str) msvcr100.atoi #don't forward to msvcrt
@ cdecl atol(str) msvcrt.atol
@ cdecl bsearch(ptr ptr long long ptr) msvcrt.bsearch
@ cdecl calloc(long long) msvcrt.calloc

View file

@ -1310,7 +1310,7 @@
@ cdecl -arch=arm,x86_64 atan2f(float float) msvcrt.atan2f
@ cdecl atexit(ptr) msvcrt.atexit
@ cdecl atof(str) msvcrt.atof
@ cdecl atoi(str) msvcrt.atoi
@ cdecl atoi(str) msvcr100.atoi #don't forward to msvcrt
@ cdecl atol(str) msvcrt.atol
@ cdecl bsearch(ptr ptr long long ptr) msvcrt.bsearch
@ cdecl bsearch_s(ptr ptr long long ptr ptr) msvcrt.bsearch_s

View file

@ -1283,7 +1283,7 @@
@ cdecl -arch=arm,x86_64 atanf(float) msvcrt.atanf
@ cdecl atexit(ptr) msvcrt.atexit
@ cdecl atof(str) msvcrt.atof
@ cdecl atoi(str) msvcrt.atoi
@ cdecl atoi(str) msvcr100.atoi ##don't forward to msvcrt
@ cdecl atol(str) msvcrt.atol
@ cdecl bsearch(ptr ptr long long ptr) msvcrt.bsearch
@ cdecl bsearch_s(ptr ptr long long ptr ptr) msvcrt.bsearch_s

View file

@ -893,7 +893,27 @@ int __cdecl MSVCRT__atoi_l(const char *str, MSVCRT__locale_t locale)
*/
int __cdecl MSVCRT_atoi(const char *str)
{
return MSVCRT__atoi_l(str, NULL);
BOOL minus = FALSE;
int ret = 0;
if(!str)
return 0;
while(isspace(*str)) str++;
if(*str == '+') {
str++;
}else if(*str == '-') {
minus = TRUE;
str++;
}
while(*str>='0' && *str<='9') {
ret = ret*10+*str-'0';
str++;
}
return minus ? -ret : ret;
}
/*********************************************************************

View file

@ -2521,6 +2521,23 @@ static void test__wcstoi64(void)
return;
}
static void test_atoi(void)
{
int r;
r = atoi("0");
ok(r == 0, "atoi(0) = %d\n", r);
r = atoi("-1");
ok(r == -1, "atoi(-1) = %d\n", r);
r = atoi("1");
ok(r == 1, "atoi(1) = %d\n", r);
r = atoi("4294967296");
ok(r == 0, "atoi(4294967296) = %d\n", r);
}
START_TEST(string)
{
char mem[100];
@ -2620,4 +2637,5 @@ START_TEST(string)
test__atodbl();
test__stricmp();
test__wcstoi64();
test_atoi();
}

View file

@ -182,6 +182,7 @@ int __cdecl abs(int);
int __cdecl atexit(void (*)(void));
double __cdecl atof(const char*);
int __cdecl atoi(const char*);
int __cdecl _atoi_l(const char*,_locale_t);
__msvcrt_long __cdecl atol(const char*);
void* __cdecl calloc(size_t,size_t);
#ifndef __i386__