diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-03-29 10:10:27 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-01 10:38:54 +0200 |
commit | 31f63c9749e6d9a5a20dadfacc9fb50cbb4cb065 (patch) | |
tree | b5dc1d5798730a274a8d27bf84ed9540ab0c8f95 /common/imd.c | |
parent | 5e335773e0814173b40873a891964a7858d64688 (diff) | |
download | barebox-31f63c9749e6d9a5a20dadfacc9fb50cbb4cb065.tar.gz barebox-31f63c9749e6d9a5a20dadfacc9fb50cbb4cb065.tar.xz |
imd: string returned from imd_string_data should be const
imd_string_data() returns the original data, so the string should be
const.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/imd.c')
-rw-r--r-- | common/imd.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/common/imd.c b/common/imd.c index acaa23fcbf..5570ae973a 100644 --- a/common/imd.c +++ b/common/imd.c @@ -193,7 +193,7 @@ static uint32_t imd_name_to_type(const char *name) return IMD_TYPE_INVALID; } -static char *imd_string_data(struct imd_header *imd, int index) +static const char *imd_string_data(struct imd_header *imd, int index) { int i, total = 0, l = 0; int len = imd_read_length(imd); @@ -306,10 +306,15 @@ int imd_command(int argc, char *argv[]) } if (imd_is_string(type)) { - if (strno >= 0) - str = imd_string_data(imd, strno); - else + if (strno >= 0) { + const char *s = imd_string_data(imd, strno); + if (s) + str = strdup(s); + else + str = NULL; + } else { str = imd_concat_strings(imd); + } if (!str) return -ENODATA; @@ -319,8 +324,7 @@ int imd_command(int argc, char *argv[]) else printf("%s\n", str); - if (strno < 0) - free(str); + free(str); } else { printf("tag 0x%08x present\n", type); } |