diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2014-03-23 12:11:18 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2014-03-23 12:11:18 +0000 |
commit | 889e182fcac9bd2312f07782277ab1e832f9bb75 (patch) | |
tree | ef250a703f800ff0d1343e6e88415733a430a57b | |
parent | ac1f227ddd1d860957c848f834ec0dfbe0dbbe83 (diff) | |
download | mandoc-889e182fcac9bd2312f07782277ab1e832f9bb75.tar.gz |
avoid repetitive code for asprintf error handling
-rw-r--r-- | mandocdb.c | 5 | ||||
-rw-r--r-- | mansearch.c | 40 | ||||
-rw-r--r-- | mdoc.c | 5 | ||||
-rw-r--r-- | mdoc_validate.c | 8 | ||||
-rw-r--r-- | roff.c | 6 |
5 files changed, 17 insertions, 47 deletions
@@ -1536,10 +1536,7 @@ parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_node *n) return(0); } - if (-1 == asprintf(&cp, "%s(%s)", n->string, n->next->string)) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&cp, "%s(%s)", n->string, n->next->string); putkey(mpage, cp, TYPE_Xr); free(cp); return(0); diff --git a/mansearch.c b/mansearch.c index 9caf434e..ff502daf 100644 --- a/mansearch.c +++ b/mansearch.c @@ -338,11 +338,8 @@ buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s, (strcmp(sec, prevsec) || strcmp(arch, prevarch))) { sep2 = '\0' == *prevarch ? "" : "/"; - if (-1 == asprintf(&newnames, "%s(%s%s%s)", - oldnames, prevsec, sep2, prevarch)) { - perror(0); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&newnames, "%s(%s%s%s)", + oldnames, prevsec, sep2, prevarch); free(mpage->names); oldnames = mpage->names = newnames; free(prevsec); @@ -359,11 +356,8 @@ buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s, /* Append the new name. */ - if (-1 == asprintf(&newnames, "%s%s%s", - oldnames, sep1, name)) { - perror(0); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&newnames, "%s%s%s", + oldnames, sep1, name); free(mpage->names); mpage->names = newnames; @@ -380,11 +374,8 @@ buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s, fsec = "0"; } sep2 = '\0' == *arch ? "" : "/"; - if (-1 == asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s", - path, sep1, sec, sep2, arch, name, fsec)) { - perror(0); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s", + path, sep1, sec, sep2, arch, name, fsec); } if (SQLITE_DONE != c) fprintf(stderr, "%s\n", sqlite3_errmsg(db)); @@ -394,11 +385,8 @@ buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s, if (NULL != prevsec) { sep2 = '\0' == *prevarch ? "" : "/"; - if (-1 == asprintf(&newnames, "%s(%s%s%s)", - mpage->names, prevsec, sep2, prevarch)) { - perror(0); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&newnames, "%s(%s%s%s)", + mpage->names, prevsec, sep2, prevarch); free(mpage->names); mpage->names = newnames; free(prevsec); @@ -427,11 +415,8 @@ buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t id, uint64_t outbit) sep1 = " # "; } data = sqlite3_column_text(s, 1); - if (-1 == asprintf(&newoutput, "%s%s%s", - oldoutput, sep1, data)) { - perror(0); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&newoutput, "%s%s%s", + oldoutput, sep1, data); free(output); output = newoutput; } @@ -603,10 +588,7 @@ exprspec(struct expr *cur, uint64_t key, const char *value, if (NULL == value) return(cur); - if (-1 == asprintf(&cp, format, value)) { - perror(0); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&cp, format, value); cur->next = mandoc_calloc(1, sizeof(struct expr)); cur = cur->next; cur->and = 1; @@ -594,10 +594,7 @@ mdoc_word_append(struct mdoc *mdoc, const char *p) n = mdoc->last; addstr = roff_strdup(mdoc->roff, p); - if (-1 == asprintf(&newstr, "%s %s", n->string, addstr)) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + mandoc_asprintf(&newstr, "%s %s", n->string, addstr); free(addstr); free(n->string); n->string = newstr; diff --git a/mdoc_validate.c b/mdoc_validate.c index 972c5ab8..0fe8b09a 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -2395,11 +2395,9 @@ post_os(POST_ARGS) if (-1 == uname(&utsname)) { mdoc_nmsg(mdoc, n, MANDOCERR_UNAME); defbuf = mandoc_strdup("UNKNOWN"); - } else if (-1 == asprintf(&defbuf, "%s %s", - utsname.sysname, utsname.release)) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + } else + mandoc_asprintf(&defbuf, "%s %s", + utsname.sysname, utsname.release); } mdoc->meta.os = mandoc_strdup(defbuf); #endif /*!OSNAME*/ @@ -656,11 +656,7 @@ roff_parsetext(char **bufp, size_t *szp, int pos, int *offs) /* Spring the input line trap. */ if (1 == roffit_lines) { - isz = asprintf(&p, "%s\n.%s", *bufp, roffit_macro); - if (-1 == isz) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + isz = mandoc_asprintf(&p, "%s\n.%s", *bufp, roffit_macro); free(*bufp); *bufp = p; *szp = isz + 1; |