This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] sim: sim_do_commandf: fix call to va_end [PR sim/19273] [committed]
- From: Mike Frysinger <vapier at gentoo dot org>
- To: gdb-patches at sourceware dot org
- Date: Sun, 22 Nov 2015 02:20:21 -0500
- Subject: [PATCH] sim: sim_do_commandf: fix call to va_end [PR sim/19273] [committed]
- Authentication-results: sourceware.org; auth=none
Make sure we call va_end even in the error case.
---
sim/common/ChangeLog | 6 ++++++
sim/common/sim-utils.c | 9 +++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 464fd80..1b21995 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,5 +1,11 @@
2015-11-21 Mike Frysinger <vapier@gentoo.org>
+ PR sim/19273
+ * sim-utils.c (sim_do_commandf): Declare ret. Call va_start,
+ vasprintf, and va_end together. Check ret after va_end call.
+
+2015-11-21 Mike Frysinger <vapier@gentoo.org>
+
* sim-types.h (SIM_PRI_TB): Define.
(PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
(PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
index 63d532d..c6f96a8 100644
--- a/sim/common/sim-utils.c
+++ b/sim/common/sim-utils.c
@@ -328,15 +328,20 @@ sim_do_commandf (SIM_DESC sd,
{
va_list ap;
char *buf;
+ int ret;
+
va_start (ap, fmt);
- if (vasprintf (&buf, fmt, ap) < 0)
+ ret = vasprintf (&buf, fmt, ap);
+ va_end (ap);
+
+ if (ret < 0)
{
sim_io_eprintf (sd, "%s: asprintf failed for `%s'\n",
STATE_MY_NAME (sd), fmt);
return;
}
+
sim_do_command (sd, buf);
- va_end (ap);
free (buf);
}
--
2.6.2