summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeung-Woo Kim <sw0312.kim@samsung.com>2020-09-04 14:57:50 +0900
committerSeung-Woo Kim <sw0312.kim@samsung.com>2020-09-04 18:41:39 +0900
commit81d10c9776624c9de698f5eff961a91af3a1286a (patch)
treefcd456f4bb4df3aaeb7b62e5417933afe49b61ea
parent4dfe82cec329355bf13d033c7eb1ea984723db24 (diff)
downloadmemps-81d10c9776624c9de698f5eff961a91af3a1286a.tar.gz
memps-81d10c9776624c9de698f5eff961a91af3a1286a.tar.bz2
memps-81d10c9776624c9de698f5eff961a91af3a1286a.zip
remove possible unsigned integer overflow for return value
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>
-rw-r--r--memps.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/memps.c b/memps.c
index c54b007..49e7035 100644
--- a/memps.c
+++ b/memps.c
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include <sys/vfs.h>
#include <linux/limits.h>
+#include <limits.h>
#include <ctype.h>
#include <stddef.h>
@@ -398,10 +399,14 @@ static unsigned total_gem_memory(void)
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;