@@ -145,11 +145,12 @@ append_trailer(FILE *out, struct fwimage_trailer *tr)
static int
add_metadata(struct fwimage_trailer *tr)
{
- struct fwimage_header hdr = {};
+ struct fwimage_header hdr;
tr->type = FWIMAGE_INFO;
tr->size = sizeof(hdr) + sizeof(*tr);
+ memset(&hdr, 0, sizeof(hdr));
trailer_update_crc(tr, &hdr, sizeof(hdr));
fwrite(&hdr, sizeof(hdr), 1, firmware_file);
@@ -181,13 +182,15 @@ add_signature(struct fwimage_trailer *tr)
static int
add_data(const char *name)
{
- struct fwimage_trailer tr = {
- .magic = cpu_to_be32(FWIMAGE_MAGIC),
- .crc32 = ~0,
- };
+ struct fwimage_trailer tr;
int file_len = 0;
int ret = 0;
+ memset(&tr, 0, sizeof(tr));
+
+ tr.crc32 = ~0;
+ tr.magic = cpu_to_be32(FWIMAGE_MAGIC);
+
firmware_file = fopen(name, "r+");
if (!firmware_file) {
msg("Failed to open firmware file\n");
@@ -289,6 +292,8 @@ extract_data(const char *name)
void *buf;
bool metadata_keep = false;
+ memset(&tr, 0, sizeof(tr));
+
firmware_file = open_file(name, false);
if (!firmware_file) {
msg("Failed to open firmware file\n");
scan-build from clang version 9 has reported following issues: crc32.h:44:32: warning: The right operand of '^' is a garbage value val = crc_table[(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); ^ ~~~~~~~~~~~~~~ cppcheck version 1.89 has reported following issues: fwtool.c:260:9: error: Uninitialized variable: dest [uninitvar] memcpy(dest, dbuf->cur + dbuf->cur_len - cur_len, cur_len); ^ fwtool.c:333:27: note: Calling function 'extract_tail', 2nd argument '&tr' value is <Uninit> if (extract_tail(&dbuf, &tr, sizeof(tr))) { ^ Signed-off-by: Petr Štetiar <ynezz@true.cz> --- fwtool.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)