#include <ctf-impl.h>
#include <string.h>
+#define str_append(s, a) ctf_str_append_noerr (s, a)
+
/* One item to be dumped, in string form. */
typedef struct ctf_dump_item
{
if (id == 0 || ctf_errno (fp) == ECTF_NONREPRESENTABLE)
{
- str = ctf_str_append (str, " (type not represented in CTF)");
+ str = str_append (str, " (type not represented in CTF)");
ctf_set_errno (fp, ECTF_NOTREF);
break;
}
}
free (buf);
buf = NULL;
- str = ctf_str_append (str, bit);
+ str = str_append (str, bit);
free (bit);
bit = NULL;
new_id = ctf_type_reference (fp, id);
if (new_id != CTF_ERR)
- str = ctf_str_append (str, " ->");
+ str = str_append (str, " ->");
} while (new_id != CTF_ERR);
if (ctf_errno (fp) != ECTF_NOTREF)
return -1; /* errno is set for us. */
}
- str = ctf_str_append (str, typestr);
+ str = str_append (str, typestr);
free (typestr);
ctf_dump_append (state, str);
return -1; /* errno is set for us. */
}
- str = ctf_str_append (str, typestr);
+ str = str_append (str, typestr);
free (typestr);
ctf_dump_append (state, str);
goto err;
}
- str = ctf_str_append (str, " ");
+ str = str_append (str, " ");
/* Function name. */
if (asprintf (&bit, "%s (0x%lx) ", sym_name, (unsigned long) i) < 0)
goto oom;
}
- str = ctf_str_append (str, bit);
- str = ctf_str_append (str, " (");
+ str = str_append (str, bit);
+ str = str_append (str, " (");
free (bit);
/* Function arguments. */
err = "look up argument type name";
goto err;
}
- str = ctf_str_append (str, bit);
+ str = str_append (str, bit);
if ((j < fi.ctc_argc - 1) || (fi.ctc_flags & CTF_FUNC_VARARG))
- str = ctf_str_append (str, ", ");
+ str = str_append (str, ", ");
free (bit);
}
if (fi.ctc_flags & CTF_FUNC_VARARG)
- str = ctf_str_append (str, "...");
- str = ctf_str_append (str, ")");
+ str = str_append (str, "...");
+ str = str_append (str, ")");
free (args);
ctf_dump_append (state, str);
return -1; /* errno is set for us. */
}
- str = ctf_str_append (str, typestr);
+ str = str_append (str, typestr);
free (typestr);
ctf_dump_append (state, str);
ssize_t i;
for (i = 0; i < depth; i++)
- *state->cdm_str = ctf_str_append (*state->cdm_str, " ");
+ *state->cdm_str = str_append (*state->cdm_str, " ");
if ((typestr = ctf_type_aname (state->cdm_fp, id)) == NULL)
{
offset) < 0)
goto oom;
- *state->cdm_str = ctf_str_append (*state->cdm_str, bit);
+ *state->cdm_str = str_append (*state->cdm_str, bit);
free (typestr);
free (bit);
return 0;
offset, id, ctf_type_kind (state->cdm_fp, id), typestr, name,
(unsigned long) ctf_type_align (state->cdm_fp, id)) < 0)
goto oom;
- *state->cdm_str = ctf_str_append (*state->cdm_str, bit);
+ *state->cdm_str = str_append (*state->cdm_str, bit);
free (typestr);
free (bit);
typestr = NULL;
if (asprintf (&bit, ", format 0x%x, offset:bits 0x%x:0x%x", ep.cte_format,
ep.cte_offset, ep.cte_bits) < 0)
goto oom;
- *state->cdm_str = ctf_str_append (*state->cdm_str, bit);
+ *state->cdm_str = str_append (*state->cdm_str, bit);
free (bit);
bit = NULL;
}
- *state->cdm_str = ctf_str_append (*state->cdm_str, ")\n");
+ *state->cdm_str = str_append (*state->cdm_str, ")\n");
return 0;
oom:
goto err;
}
- str = ctf_str_append (str, "\n");
+ str = str_append (str, "\n");
if ((ctf_type_visit (state->cds_fp, id, ctf_dump_member, &membstate)) < 0)
{
if (id == 0 || ctf_errno (state->cds_fp) == ECTF_NONREPRESENTABLE)
nline[0] = '\0';
ret = func (sect, line, arg);
- str = ctf_str_append (str, ret);
- str = ctf_str_append (str, "\n");
+ str = str_append (str, ret);
+ str = str_append (str, "\n");
if (ret != line)
free (ret);
str[len-1] = '\0';
}
else
- str = strdup (state->cds_current->cdi_item);
+ {
+ str = strdup (state->cds_current->cdi_item);
+ if (!str)
+ {
+ ctf_set_errno (fp, ENOMEM);
+ return str;
+ }
+ }
ctf_set_errno (fp, 0);
return str;