=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.208 retrieving revision 1.210 diff -u -p -r1.208 -r1.210 --- mandoc/mandocdb.c 2015/11/07 14:22:29 1.208 +++ mandoc/mandocdb.c 2015/12/15 17:38:45 1.210 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.208 2015/11/07 14:22:29 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.210 2015/12/15 17:38:45 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2015 Ingo Schwarze @@ -420,9 +420,11 @@ mandocdb(int argc, char *argv[]) argv += optind; #if HAVE_PLEDGE - if (nodb && pledge("stdio rpath", NULL) == -1) { - perror("pledge"); - return (int)MANDOCLEVEL_SYSERR; + if (nodb) { + if (pledge("stdio rpath", NULL) == -1) { + perror("pledge"); + return (int)MANDOCLEVEL_SYSERR; + } } #endif @@ -452,11 +454,12 @@ mandocdb(int argc, char *argv[]) * all files specified on the command-line. */ #if HAVE_PLEDGE - if (!nodb && pledge("stdio rpath wpath cpath fattr flock", - NULL) == -1) { - perror("pledge"); - exitcode = (int)MANDOCLEVEL_SYSERR; - goto out; + if (!nodb) { + if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) { + perror("pledge"); + exitcode = (int)MANDOCLEVEL_SYSERR; + goto out; + } } #endif use_all = 1; @@ -1291,7 +1294,9 @@ parse_cat(struct mpage *mpage, int fd) { FILE *stream; char *line, *p, *title; - size_t len, plen, titlesz; + size_t linesz, plen, titlesz; + ssize_t len; + int offs; stream = (-1 == fd) ? fopen(mpage->mlinks->file, "r") : @@ -1304,10 +1309,13 @@ parse_cat(struct mpage *mpage, int fd) return; } + line = NULL; + linesz = 0; + /* Skip to first blank line. */ - while (NULL != (line = fgetln(stream, &len))) - if ('\n' == *line) + while (getline(&line, &linesz, stream) != -1) + if (*line == '\n') break; /* @@ -1315,8 +1323,8 @@ parse_cat(struct mpage *mpage, int fd) * is the first section header. Skip to it. */ - while (NULL != (line = fgetln(stream, &len))) - if ('\n' != *line && ' ' != *line) + while (getline(&line, &linesz, stream) != -1) + if (*line != '\n' && *line != ' ') break; /* @@ -1329,20 +1337,20 @@ parse_cat(struct mpage *mpage, int fd) titlesz = 0; title = NULL; - while (NULL != (line = fgetln(stream, &len))) { - if (' ' != *line || '\n' != line[len - 1]) + while ((len = getline(&line, &linesz, stream)) != -1) { + if (*line != ' ') break; - while (len > 0 && isspace((unsigned char)*line)) { - line++; - len--; - } - if (1 == len) + offs = 0; + while (isspace((unsigned char)line[offs])) + offs++; + if (line[offs] == '\0') continue; - title = mandoc_realloc(title, titlesz + len); - memcpy(title + titlesz, line, len); - titlesz += len; + title = mandoc_realloc(title, titlesz + len - offs); + memcpy(title + titlesz, line + offs, len - offs); + titlesz += len - offs; title[titlesz - 1] = ' '; } + free(line); /* * If no page content can be found, or the input line @@ -1360,8 +1368,7 @@ parse_cat(struct mpage *mpage, int fd) return; } - title = mandoc_realloc(title, titlesz + 1); - title[titlesz] = '\0'; + title[titlesz - 1] = '\0'; /* * Skip to the first dash.