[flashrom] [PATCH] flashrom.c: Use correct size in `calloc()`
Stefan Tauner
stefan.tauner at alumni.tuwien.ac.at
Tue Jan 20 08:59:58 CET 2015
On Mon, 19 Jan 2015 23:20:23 +0100
Paul Menzel <paulepanter at users.sourceforge.net> wrote:
> 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... ");
Thanks for your patch. The right thing would be to use uint8_t
actually... but since flashrom is POSIX-compatible sizeof(uint8_t) ==
sizeof(char) == sizeof(unsigned char) == 8... so I'll leave this as is
for now and may change it later to uint8_t someday.
--
Kind regards/Mit freundlichen Grüßen, Stefan Tauner
More information about the flashrom
mailing list