sim: sim_do_commandf: fix call to va_end [PR sim/19273]
authorMike Frysinger <vapier@gentoo.org>
Sun, 22 Nov 2015 07:10:04 +0000 (23:10 -0800)
committerMike Frysinger <vapier@gentoo.org>
Sun, 22 Nov 2015 07:15:28 +0000 (02:15 -0500)
Make sure we call va_end even in the error case.

sim/common/ChangeLog
sim/common/sim-utils.c

index 464fd80e1debe3f3735f550fe1be1fcc7edcdb7e..1b219950e628b7bf7da76bcef1aa7ac3da207547 100644 (file)
@@ -1,3 +1,9 @@
+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.
index 63d532df5052c9344888746169d1c7646550acce..c6f96a8a07fbe514d8c5234bad825a9bb9c5c39d 100644 (file)
@@ -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);
 }
 
This page took 0.02737 seconds and 4 git commands to generate.