Use xasprintf() in srcpos
Now that we have an xasprintf() helper function, use it to simplify the srcpos_string() implementation. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9dc404958e
commit
d71d25d760
1 changed files with 8 additions and 12 deletions
20
srcpos.c
20
srcpos.c
|
@ -266,26 +266,22 @@ srcpos_string(struct srcpos *pos)
|
||||||
{
|
{
|
||||||
const char *fname = "<no-file>";
|
const char *fname = "<no-file>";
|
||||||
char *pos_str;
|
char *pos_str;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (pos)
|
if (pos)
|
||||||
fname = pos->file->name;
|
fname = pos->file->name;
|
||||||
|
|
||||||
|
|
||||||
if (pos->first_line != pos->last_line)
|
if (pos->first_line != pos->last_line)
|
||||||
rc = asprintf(&pos_str, "%s:%d.%d-%d.%d", fname,
|
xasprintf(&pos_str, "%s:%d.%d-%d.%d", fname,
|
||||||
pos->first_line, pos->first_column,
|
pos->first_line, pos->first_column,
|
||||||
pos->last_line, pos->last_column);
|
pos->last_line, pos->last_column);
|
||||||
else if (pos->first_column != pos->last_column)
|
else if (pos->first_column != pos->last_column)
|
||||||
rc = asprintf(&pos_str, "%s:%d.%d-%d", fname,
|
xasprintf(&pos_str, "%s:%d.%d-%d", fname,
|
||||||
pos->first_line, pos->first_column,
|
pos->first_line, pos->first_column,
|
||||||
pos->last_column);
|
pos->last_column);
|
||||||
else
|
else
|
||||||
rc = asprintf(&pos_str, "%s:%d.%d", fname,
|
xasprintf(&pos_str, "%s:%d.%d", fname,
|
||||||
pos->first_line, pos->first_column);
|
pos->first_line, pos->first_column);
|
||||||
|
|
||||||
if (rc == -1)
|
|
||||||
die("Couldn't allocate in srcpos string");
|
|
||||||
|
|
||||||
return pos_str;
|
return pos_str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue