[flashrom] [PATCH] flashrom.c: Use correct size in `calloc()`

Paul Menzel paulepanter at users.sourceforge.net
Mon Jan 19 23:20:23 CET 2015


Date: Mon, 19 Jan 2015 23:08:59 +0100

Fix the warning below found by Clang’s static analyzer scan-build
3.6 and use `sizeof(unsigned char)` as the size argument.

	flashrom.c:1304:23: warning: Result of 'calloc' is converted to a pointer of type 'unsigned char', which is incompatible with sizeof operand type 'char'
		unsigned char *buf = calloc(size, sizeof(char));
		~~~~~~~~~~~~~~~      ^~~~~~       ~~~~~~~~~~~~
	1 warning generated.

Signed-off-by: Paul Menzel <paulepanter at users.sourceforge.net>
---
 flashrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flashrom.c b/flashrom.c
index 9df1478..5ef22b0 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1301,7 +1301,7 @@ int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *
 int read_flash_to_file(struct flashctx *flash, const char *filename)
 {
 	unsigned long size = flash->chip->total_size * 1024;
-	unsigned char *buf = calloc(size, sizeof(char));
+	unsigned char *buf = calloc(size, sizeof(unsigned char));
 	int ret = 0;
 
 	msg_cinfo("Reading flash... ");
-- 
2.1.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://www.flashrom.org/pipermail/flashrom/attachments/20150119/42a1ff08/attachment.asc>


More information about the flashrom mailing list