From 378495dcc88b4d5c4ae1210f3c72c037a42187d8 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 10 Dec 2014 14:03:28 +1100 Subject: Fix bug/warning in hdata/memory.c I introduced in f1a3a19 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passing the wrong parameter to snprintf (sizeof(char*)) rather than actual length of the string. GCC 4.9 told us about it (and broke make check when I enabled -Werror) hdata/test/../memory.c: In function ‘add_address_range’: hdata/test/../memory.c:144:23: error: argument to ‘sizeof’ in ‘snprintf’ call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess] Signed-off-by: Stewart Smith --- hdata/memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'hdata') diff --git a/hdata/memory.c b/hdata/memory.c index cf336a0..18beb3b 100644 --- a/hdata/memory.c +++ b/hdata/memory.c @@ -118,8 +118,9 @@ static bool add_address_range(struct dt_node *root, u64 reg[2]; char *name; u32 chip_id; + size_t namesz = sizeof("memory@") + STR_MAX_CHARS(reg[0]); - name = (char*)malloc(sizeof("memory@") + STR_MAX_CHARS(reg[0])); + name = (char*)malloc(namesz); prlog(PR_DEBUG, " Range: 0x%016llx..0x%016llx " "on Chip 0x%x mattr: 0x%x\n", @@ -141,7 +142,7 @@ static bool add_address_range(struct dt_node *root, return true; } } - snprintf(name, sizeof(name), "memory@%llx", (long long)reg[0]); + snprintf(name, namesz, "memory@%llx", (long long)reg[0]); mem = dt_new(root, name); dt_add_property_string(mem, "device_type", "memory"); -- cgit v1.1