From 6bf8542dd52f062dbaafa40460d9b82c2d28d3df Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 4 Mar 2003 04:40:01 +0000 Subject: [PATCH] Fixed int conversion in GetPrivateProfileInt so that all the tests succeed. --- files/profile.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/files/profile.c b/files/profile.c index 277e811a3bf..02847c4ddf8 100644 --- a/files/profile.c +++ b/files/profile.c @@ -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; } /***********************************************************************