Commit f40fd895 by Uros Bizjak Committed by Uros Bizjak

jit-recording.c (dump::write): Also check vasprintf return value.

	* jit-recording.c (dump::write): Also check vasprintf return value.
	(recording::context::add_error_va): Ditto.
	(recording::string::from_printf): Ditto.

From-SVN: r221426
parent 18eb0d13
2015-03-13 Uros Bizjak <ubizjak@gmail.com>
* jit-recording.c (dump::write): Also check vasprintf return value.
(recording::context::add_error_va): Ditto.
(recording::string::from_printf): Ditto.
2015-03-13 David Malcolm <dmalcolm@redhat.com> 2015-03-13 David Malcolm <dmalcolm@redhat.com>
* docs/internals/index.rst (Packaging notes): New section. * docs/internals/index.rst (Packaging notes): New section.
......
...@@ -77,8 +77,9 @@ dump::~dump () ...@@ -77,8 +77,9 @@ dump::~dump ()
void void
dump::write (const char *fmt, ...) dump::write (const char *fmt, ...)
{ {
int len;
va_list ap; va_list ap;
char *buf = NULL; char *buf;
/* If there was an error opening the file, we've already reported it. /* If there was an error opening the file, we've already reported it.
Don't attempt further work. */ Don't attempt further work. */
...@@ -86,10 +87,10 @@ dump::write (const char *fmt, ...) ...@@ -86,10 +87,10 @@ dump::write (const char *fmt, ...)
return; return;
va_start (ap, fmt); va_start (ap, fmt);
vasprintf (&buf, fmt, ap); len = vasprintf (&buf, fmt, ap);
va_end (ap); va_end (ap);
if (!buf) if (buf == NULL || len < 0)
{ {
m_ctxt.add_error (NULL, "malloc failure writing to dumpfile %s", m_ctxt.add_error (NULL, "malloc failure writing to dumpfile %s",
m_filename); m_filename);
...@@ -1231,22 +1232,23 @@ recording::context::add_error (location *loc, const char *fmt, ...) ...@@ -1231,22 +1232,23 @@ recording::context::add_error (location *loc, const char *fmt, ...)
void void
recording::context::add_error_va (location *loc, const char *fmt, va_list ap) recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
{ {
int len;
char *malloced_msg; char *malloced_msg;
const char *errmsg; const char *errmsg;
bool has_ownership; bool has_ownership;
JIT_LOG_SCOPE (get_logger ()); JIT_LOG_SCOPE (get_logger ());
vasprintf (&malloced_msg, fmt, ap); len = vasprintf (&malloced_msg, fmt, ap);
if (malloced_msg) if (malloced_msg == NULL || len < 0)
{ {
errmsg = malloced_msg; errmsg = "out of memory generating error message";
has_ownership = true; has_ownership = false;
} }
else else
{ {
errmsg = "out of memory generating error message"; errmsg = malloced_msg;
has_ownership = false; has_ownership = true;
} }
if (get_logger ()) if (get_logger ())
get_logger ()->log ("error %i: %s", m_error_count, errmsg); get_logger ()->log ("error %i: %s", m_error_count, errmsg);
...@@ -1709,15 +1711,16 @@ recording::string::~string () ...@@ -1709,15 +1711,16 @@ recording::string::~string ()
recording::string * recording::string *
recording::string::from_printf (context *ctxt, const char *fmt, ...) recording::string::from_printf (context *ctxt, const char *fmt, ...)
{ {
int len;
va_list ap; va_list ap;
char *buf = NULL; char *buf;
recording::string *result; recording::string *result;
va_start (ap, fmt); va_start (ap, fmt);
vasprintf (&buf, fmt, ap); len = vasprintf (&buf, fmt, ap);
va_end (ap); va_end (ap);
if (!buf) if (buf == NULL || len < 0)
{ {
ctxt->add_error (NULL, "malloc failure"); ctxt->add_error (NULL, "malloc failure");
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment