diff options
author | Mikhail Ilin <ilin.mikhail.ol@gmail.com> | 2022-11-23 12:39:36 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-12-08 09:29:01 -0500 |
commit | 17f8a7487689ad727aadc00c14cd3315cd880e4a (patch) | |
tree | 8b812e163eb000b55f8873091b6942794b6d4b2f /tools/mkimage.c | |
parent | 04e6332ec0b139a0b7452551455ae96428c7d1ef (diff) |
tools: mkimage: Fix nullptr at strchr()
The copy_datafile(ifd, params.datafile) function has been
implemented to copy data by reducing the number of lines in the main
function.
Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com>
Diffstat (limited to 'tools/mkimage.c')
-rw-r--r-- | tools/mkimage.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/tools/mkimage.c b/tools/mkimage.c index 30c6df7708..0b5ee5da1e 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -430,6 +430,25 @@ static void verify_image(const struct image_type_params *tparams) (void)close(ifd); } +void copy_datafile(int ifd, char *file) +{ + if (!file) + return; + for (;;) { + char *sep = strchr(file, ':'); + + if (sep) { + *sep = '\0'; + copy_file(ifd, file, 1); + *sep++ = ':'; + file = sep; + } else { + copy_file(ifd, file, 0); + break; + } + } +} + int main(int argc, char **argv) { int ifd = -1; @@ -647,21 +666,7 @@ int main(int argc, char **argv) file = NULL; } } - - file = params.datafile; - - for (;;) { - char *sep = strchr(file, ':'); - if (sep) { - *sep = '\0'; - copy_file (ifd, file, 1); - *sep++ = ':'; - file = sep; - } else { - copy_file (ifd, file, 0); - break; - } - } + copy_datafile(ifd, params.datafile); } else if (params.type == IH_TYPE_PBLIMAGE) { /* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, ¶ms); |