diff mbox series

[v3] tools: mkimage: Fix nullptr at strchr()

Message ID 20221123093936.19949-1-ilin.mikhail.ol@gmail.com
State Awaiting Upstream
Delegated to: Tom Rini
Headers show
Series [v3] tools: mkimage: Fix nullptr at strchr() | expand

Commit Message

Mikhail Ilin Nov. 23, 2022, 9:39 a.m. UTC
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>
---
 tools/mkimage.c | 35 +++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

Comments

Tom Rini Dec. 8, 2022, 8:23 p.m. UTC | #1
On Wed, Nov 23, 2022 at 12:39:36PM +0300, Mikhail Ilin wrote:

> 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>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/tools/mkimage.c b/tools/mkimage.c
index 30c6df7708..0b68a29285 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -430,6 +430,24 @@  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, &params);