From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Juergen Gross <jgross@suse.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Olaf Hering <olaf@aepfle.de>, Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH] xen-detect: handle asprintf error
Date: Wed, 21 Jun 2017 15:41:52 +0100 [thread overview]
Message-ID: <20170621144152.13065-1-wei.liu2@citrix.com> (raw)
Otherwise gcc with -Wunused will complain the return value is not
used.
Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Olaf Hering <olaf@aepfle.de>
Cc: Juergen Gross <jgross@suse.com>
---
tools/misc/xen-detect.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tools/misc/xen-detect.c b/tools/misc/xen-detect.c
index a62747d316..fd187a4be6 100644
--- a/tools/misc/xen-detect.c
+++ b/tools/misc/xen-detect.c
@@ -90,8 +90,15 @@ static int check_for_xen(int pv_context)
found:
cpuid(base + 1, regs, pv_context);
if ( regs[0] )
- asprintf(&ver, "V%u.%u",
- (uint16_t)(regs[0] >> 16), (uint16_t)regs[0]);
+ {
+ int r = asprintf(&ver, "V%u.%u", (uint16_t)(regs[0] >> 16),
+ (uint16_t)regs[0]);
+ if ( r < 0 )
+ {
+ perror("asprintf failed\n");
+ exit(EXIT_FAILURE);
+ }
+ }
return regs[0];
}
@@ -193,8 +200,14 @@ static enum guest_type check_sysfs(void)
if ( tmp )
tmp[strlen(tmp) - 1] = 0;
if ( str && tmp )
- asprintf(&ver, "V%s.%s", str, tmp);
- else
+ {
+ int r = asprintf(&ver, "V%s.%s", str, tmp);
+ if ( r < 0 )
+ {
+ perror("asprintf failed\n");
+ exit(EXIT_FAILURE);
+ }
+ } else
ver = strdup("unknown version");
free(tmp);
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next reply other threads:[~2017-06-21 14:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 14:41 Wei Liu [this message]
2017-06-23 14:30 ` [PATCH] xen-detect: handle asprintf error Andrew Cooper
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=20170621144152.13065-1-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jgross@suse.com \
--cc=olaf@aepfle.de \
--cc=xen-devel@lists.xenproject.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;
as well as URLs for NNTP newsgroup(s).