From d71d25d76012896521f937bf0c69f27b1a37cdc2 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 25 May 2016 15:15:36 +1000 Subject: [PATCH] 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 --- srcpos.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/srcpos.c b/srcpos.c index f534c22..af7fb3c 100644 --- a/srcpos.c +++ b/srcpos.c @@ -266,26 +266,22 @@ srcpos_string(struct srcpos *pos) { const char *fname = ""; 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; }