forked from openGauss-Ecosystem/openGauss-server
!2740 函数StrToInt32内部判断范围代码无效
Merge pull request !2740 from foolishlee/StrToInt32
This commit is contained in:
commit
da120693c6
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue