=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mandocdb.c,v retrieving revision 1.161 retrieving revision 1.162 diff -c -r1.161 -r1.162 *** src/usr.bin/mandoc/mandocdb.c 2015/11/06 16:27:13 1.161 --- src/usr.bin/mandoc/mandocdb.c 2015/11/07 17:58:52 1.162 *************** *** 1,4 **** ! /* $OpenBSD: mandocdb.c,v 1.161 2015/11/06 16:27:13 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2015 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: mandocdb.c,v 1.162 2015/11/07 17:58:52 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2015 Ingo Schwarze *************** *** 1269,1275 **** { FILE *stream; char *line, *p, *title; ! size_t len, plen, titlesz; stream = (-1 == fd) ? fopen(mpage->mlinks->file, "r") : --- 1269,1277 ---- { FILE *stream; char *line, *p, *title; ! size_t linesz, plen, titlesz; ! ssize_t len; ! int offs; stream = (-1 == fd) ? fopen(mpage->mlinks->file, "r") : *************** *** 1282,1291 **** return; } /* Skip to first blank line. */ ! while (NULL != (line = fgetln(stream, &len))) ! if ('\n' == *line) break; /* --- 1284,1296 ---- return; } + line = NULL; + linesz = 0; + /* Skip to first blank line. */ ! while (getline(&line, &linesz, stream) != -1) ! if (*line == '\n') break; /* *************** *** 1293,1300 **** * is the first section header. Skip to it. */ ! while (NULL != (line = fgetln(stream, &len))) ! if ('\n' != *line && ' ' != *line) break; /* --- 1298,1305 ---- * is the first section header. Skip to it. */ ! while (getline(&line, &linesz, stream) != -1) ! if (*line != '\n' && *line != ' ') break; /* *************** *** 1307,1326 **** titlesz = 0; title = NULL; ! while (NULL != (line = fgetln(stream, &len))) { ! if (' ' != *line || '\n' != line[len - 1]) break; ! while (len > 0 && isspace((unsigned char)*line)) { ! line++; ! len--; ! } ! if (1 == len) continue; ! title = mandoc_realloc(title, titlesz + len); ! memcpy(title + titlesz, line, len); ! titlesz += len; title[titlesz - 1] = ' '; } /* * If no page content can be found, or the input line --- 1312,1331 ---- titlesz = 0; title = NULL; ! while ((len = getline(&line, &linesz, stream)) != -1) { ! if (*line != ' ') break; ! offs = 0; ! while (isspace((unsigned char)line[offs])) ! offs++; ! if (line[offs] == '\0') continue; ! 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 *************** *** 1338,1345 **** return; } ! title = mandoc_realloc(title, titlesz + 1); ! title[titlesz] = '\0'; /* * Skip to the first dash. --- 1343,1349 ---- return; } ! title[titlesz - 1] = '\0'; /* * Skip to the first dash.