+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>
* docs/internals/index.rst (Packaging notes): New section.
void
dump::write (const char *fmt, ...)
{
+ int len;
va_list ap;
- char *buf = NULL;
+ char *buf;
/* If there was an error opening the file, we've already reported it.
Don't attempt further work. */
return;
va_start (ap, fmt);
- vasprintf (&buf, fmt, ap);
+ len = vasprintf (&buf, fmt, ap);
va_end (ap);
- if (!buf)
+ if (buf == NULL || len < 0)
{
m_ctxt.add_error (NULL, "malloc failure writing to dumpfile %s",
m_filename);
void
recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
{
+ int len;
char *malloced_msg;
const char *errmsg;
bool has_ownership;
JIT_LOG_SCOPE (get_logger ());
- vasprintf (&malloced_msg, fmt, ap);
- if (malloced_msg)
+ len = vasprintf (&malloced_msg, fmt, ap);
+ if (malloced_msg == NULL || len < 0)
{
- errmsg = malloced_msg;
- has_ownership = true;
+ errmsg = "out of memory generating error message";
+ has_ownership = false;
}
else
{
- errmsg = "out of memory generating error message";
- has_ownership = false;
+ errmsg = malloced_msg;
+ has_ownership = true;
}
if (get_logger ())
get_logger ()->log ("error %i: %s", m_error_count, errmsg);
recording::string *
recording::string::from_printf (context *ctxt, const char *fmt, ...)
{
+ int len;
va_list ap;
- char *buf = NULL;
+ char *buf;
recording::string *result;
va_start (ap, fmt);
- vasprintf (&buf, fmt, ap);
+ len = vasprintf (&buf, fmt, ap);
va_end (ap);
- if (!buf)
+ if (buf == NULL || len < 0)
{
ctxt->add_error (NULL, "malloc failure");
return NULL;