diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2016-05-25 15:15:36 +1000 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2016-05-25 15:15:36 +1000 |
commit | d71d25d76012896521f937bf0c69f27b1a37cdc2 (patch) | |
tree | 18bfe4f5f168ec5357bbef21822f40af7dd26d22 /srcpos.c | |
parent | 9dc404958e9c91f33f75450f69b690a5e676af04 (diff) | |
download | dtc-d71d25d76012896521f937bf0c69f27b1a37cdc2.zip dtc-d71d25d76012896521f937bf0c69f27b1a37cdc2.tar.gz dtc-d71d25d76012896521f937bf0c69f27b1a37cdc2.tar.bz2 |
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>
Diffstat (limited to 'srcpos.c')
-rw-r--r-- | srcpos.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -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; } |