Browse Source

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>
main
David Gibson 9 years ago
parent
commit
d71d25d760
  1. 20
      srcpos.c

20
srcpos.c

@ -266,26 +266,22 @@ srcpos_string(struct srcpos *pos) @@ -266,26 +266,22 @@ srcpos_string(struct srcpos *pos)
{
const char *fname = "<no-file>";
char *pos_str;
int rc;

if (pos)
fname = pos->file->name;


if (pos->first_line != pos->last_line)
rc = asprintf(&pos_str, "%s:%d.%d-%d.%d", fname,
pos->first_line, pos->first_column,
pos->last_line, pos->last_column);
xasprintf(&pos_str, "%s:%d.%d-%d.%d", fname,
pos->first_line, pos->first_column,
pos->last_line, pos->last_column);
else if (pos->first_column != pos->last_column)
rc = asprintf(&pos_str, "%s:%d.%d-%d", fname,
pos->first_line, pos->first_column,
pos->last_column);
xasprintf(&pos_str, "%s:%d.%d-%d", fname,
pos->first_line, pos->first_column,
pos->last_column);
else
rc = asprintf(&pos_str, "%s:%d.%d", fname,
pos->first_line, pos->first_column);

if (rc == -1)
die("Couldn't allocate in srcpos string");
xasprintf(&pos_str, "%s:%d.%d", fname,
pos->first_line, pos->first_column);

return pos_str;
}

Loading…
Cancel
Save