-/* $OpenBSD: deroff.c,v 1.17 2023/03/08 04:43:10 guenther Exp $ */
+/* $OpenBSD: deroff.c,v 1.18 2023/09/27 21:06:33 millert Exp $ */
/*-
* Copyright (c) 1988, 1993
char chars[128]; /* SPECIAL, PUNCT, APOS, DIGIT, or LETTER */
-char line[LINE_MAX];
+size_t linesz;
+char *line;
char *lp;
int c;
files[0] = infile;
filesp = &files[0];
+ linesz = LINE_MAX;
+ if ((line = malloc(linesz)) == NULL)
+ err(1, NULL);
+
for (i = 'a'; i <= 'z'; ++i)
chars[i] = LETTER;
for (i = 'A'; i <= 'Z'; ++i)
line[0] = c;
lp = line;
- while (lp - line < sizeof(line)) {
+ for (;;) {
+ if (lp - line == linesz - 1) {
+ char *newline = reallocarray(line, linesz, 2);
+ if (newline == NULL)
+ err(1, NULL);
+ lp = newline + (lp - line);
+ line = newline;
+ linesz *= 2;
+ }
if (c == '\\') {
*lp = ' ';
backsl();