Fixed int conversion in GetPrivateProfileInt so that all the tests

succeed.
This commit is contained in:
Alexandre Julliard 2003-03-04 04:40:01 +00:00
parent 7d6096480a
commit 6bf8542dd5
1 changed files with 19 additions and 6 deletions

View File

@ -1300,7 +1300,9 @@ UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry,
INT def_val, LPCSTR filename )
{
char buffer[20];
long result;
UINT result = 0;
char *p = buffer;
int negative = 0;
if (!GetPrivateProfileStringA( section, entry, "",
buffer, sizeof(buffer), filename ))
@ -1312,11 +1314,22 @@ UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry,
* else gets broken that way. */
if (!buffer[0]) return (UINT)def_val;
/* Don't use strtol() here !
* (returns LONG_MAX/MIN on overflow instead of "proper" overflow)
YES, scan for unsigned format ! (otherwise compatibility error) */
if (!sscanf(buffer, "%lu", &result)) return 0;
return (UINT)result;
/* do the conversion by hand to make sure
* overflow is *not* handled properly ;-) */
while (*p && isspace(*p)) p++;
if (*p == '-')
{
negative = 1;
p++;
}
else if (*p == '+') p++;
while (*p && isdigit(*p))
{
result = result * 10 + *p - '0';
p++;
}
return negative ? (UINT)-result : result;
}
/***********************************************************************