!2740 函数StrToInt32内部判断范围代码无效

Merge pull request !2740 from foolishlee/StrToInt32
This commit is contained in:
opengauss-bot 2023-01-05 02:59:41 +00:00 committed by Gitee
commit da120693c6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 4 additions and 2 deletions

View File

@ -8442,6 +8442,7 @@ char* scan_dir(DIR* dir, const char* dirpath, const char* pattern, long* filesiz
bool StrToInt32(const char* s, int *val)
{
/* set val to zero */
int64 _val = 0;
*val = 0;
int base = 10;
const char* ptr = s;
@ -8450,11 +8451,12 @@ bool StrToInt32(const char* s, int *val)
if (isdigit((unsigned char)*ptr) == 0)
return false;
int8 digit = (*ptr++ - '0');
*val = *val * base + digit;
if (*val > PG_INT32_MAX || *val < PG_INT32_MIN) {
_val = _val * base + digit;
if (_val > PG_INT32_MAX || _val < PG_INT32_MIN) {
return false;
}
}
*val = (int)_val;
return true;
}