From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH master 2/3] scripts: kwbimage: check return value of asprintf
Date: Wed, 31 May 2023 08:27:02 +0200 [thread overview]
Message-ID: <20230531062703.670521-2-ahmad@a3f.at> (raw)
In-Reply-To: <20230531062703.670521-1-ahmad@a3f.at>
Some newer toolchains defines asprintf with a must_check attribute,
leading to warnings when compiling kwbimage. Let's handle OOM gracefully
to get rid of the warnings.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
scripts/kwbimage.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index f9d052752d79..370c54c983b5 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -1006,6 +1006,7 @@ static int image_create_config_parse_oneline(char *line,
char *configpath)
{
char *keyword, *saveptr;
+ int ret;
keyword = strtok_r(line, " ", &saveptr);
if (!strcmp(keyword, "VERSION")) {
@@ -1056,10 +1057,16 @@ static int image_create_config_parse_oneline(char *line,
int argi = 0;
el->type = IMAGE_CFG_BINARY;
- if (*value == '/')
+ if (*value == '/') {
el->binary.file = strdup(value);
- else
- asprintf(&el->binary.file, "%s/%s", configpath, value);
+ } else {
+ ret = asprintf(&el->binary.file, "%s/%s", configpath, value);
+ if (ret < 0) {
+ fprintf(stderr, "Cannot allocate memory\n");
+ return -1;
+ }
+ }
+
while (1) {
value = strtok_r(NULL, " ", &saveptr);
if (!value)
--
2.38.5
next prev parent reply other threads:[~2023-05-31 6:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 6:27 [PATCH master 1/3] ARM: rockchip: pine64-quartz64: add sdram-init.bin to .gitignore Ahmad Fatoum
2023-05-31 6:27 ` Ahmad Fatoum [this message]
2023-05-31 6:27 ` [PATCH master 3/3] scripts: omap3-usb-loader: fix heap overflow Ahmad Fatoum
2023-05-31 7:28 ` [PATCH master 1/3] ARM: rockchip: pine64-quartz64: add sdram-init.bin to .gitignore Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230531062703.670521-2-ahmad@a3f.at \
--to=ahmad@a3f.at \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox