Fix improper use of memset.
For the following code snippet -
char *str;
str = (char *)malloc(...);
memset(str, '\0', sizeof(str));
^^^^^^^^^^^ always equals 4 or 8
TEST=Built.
BUG=None
Change-Id: I42fb6c27a2bd8cdbeb4941d8b01e242132132154
Reviewed-on: https://gerrit.chromium.org/gerrit/47191
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Tested-by: Han Shen <shenhan@google.com>
Commit-Queue: Han Shen <shenhan@google.com>
diff --git a/fmap_csum.c b/fmap_csum.c
index c443a62..bdf7fb5 100644
--- a/fmap_csum.c
+++ b/fmap_csum.c
@@ -58,9 +58,10 @@
char *str;
char tmp[3];
unsigned int i;
+ int strlength = len * 2 + 1;
- str = malloc((len * 2) + 1);
- memset(str, '\0', sizeof(str));
+ str = malloc(strlength);
+ memset(str, '\0', strlength);
for (i = 0; i < len; i++) {
snprintf(tmp, 3, "%02x", digest[i]);
strncat(str, tmp, 3);