update common.c.

Signed-off-by: hehedaddd <1780243524@qq.com>
This commit is contained in:
hehedaddd 2023-07-17 12:16:04 +00:00 committed by Gitee
parent 124db06be9
commit 74ae05575f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 9 additions and 7 deletions

View File

@ -447,12 +447,14 @@ int check_dir(char *dirname)
void check_overflow(unsigned int val1, unsigned int val2, void check_overflow(unsigned int val1, unsigned int val2,
unsigned int val3) unsigned int val3)
{ {
if ((unsigned long long) val1 * (unsigned long long) val2 * if ((val1 != 0) && (val2 != 0) && (val3 != 0) &&
(unsigned long long) val3 > UINT_MAX) { (((unsigned long long) UINT_MAX / (unsigned long long) val1 <
(unsigned long long) val2) ||
((unsigned long long) UINT_MAX / ((unsigned long long) val1 * (unsigned long long) val2) <
(unsigned long long) val3))) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Overflow detected (%llu). Aborting...\n", fprintf(stderr, "%s: Overflow detected (%u,%u,%u). Aborting...\n",
__FUNCTION__, (unsigned long long) val1 * (unsigned long long) val2 * __FUNCTION__, val1, val2, val3);
(unsigned long long) val3);
#endif #endif
exit(4); exit(4);
} }