Static analysis tool warns about possible overflowed return value.
During calculation, check the possible overflow for return value.
Change-Id: I676a28670249ffc10462254d60d22a8859498ec4
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
#include <sys/types.h>
#include <sys/vfs.h>
#include <linux/limits.h>
+#include <limits.h>
#include <ctype.h>
#include <stddef.h>
return 0;
}
- while (fgets(line, BUF_MAX, gem_fp) != NULL)
+ while (fgets(line, BUF_MAX, gem_fp) != NULL) {
if (sscanf(line, "%d %d %d %d\n",
- &name, &size, &handles, &refcount) == 4)
- total_gem_mem += size;
+ &name, &size, &handles, &refcount) == 4) {
+ if (total_gem_mem <= UINT_MAX - size) {
+ total_gem_mem += size;
+ }
+ }
+ }
fclose(gem_fp);
return total_gem_mem;