From 2f6855a6aa8d55d8341f454f87cabc784a890193 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Sun, 8 Jan 2023 23:28:39 +0100 Subject: [PATCH] tools: mkimage: Print human readable error when -d is not specified MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When asking mkimage to create a new image file and option -d is not specified then mkimage show human unfriendly error message: mkimage: Can't open (null): Bad address Without debugger it is hard to debug what is the issue. Function open() is being called with file name set to NULL. So add a check for this and if it happens then show human readable message that option -d was not specified. Signed-off-by: Pali Rohár --- tools/mkimage.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/mkimage.c b/tools/mkimage.c index 0b34215..5e0bb91 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -600,6 +600,11 @@ int main(int argc, char **argv) } if ((params.type != IH_TYPE_MULTI) && (params.type != IH_TYPE_SCRIPT)) { + if (!params.datafile) { + fprintf(stderr, "%s: Option -d with image data file was not specified\n", + params.cmdname); + exit(EXIT_FAILURE); + } dfd = open(params.datafile, O_RDONLY | O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", -- 2.7.4