From 16e15867f94241f357b39dc7aa84788af87fd698 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 18 Sep 2014 20:39:36 -0700 Subject: Fix double evaluation in .SH, .SS and .M2SS. The add_index function's interface changes so that it returns the result of scan_troff. The caller can use that instead of doing a redundant scan_troff which causes trouble when the text contains side effects like incrementing counters. --- man2html/man2html.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/man2html/man2html.c b/man2html/man2html.c index 7a7ef56..8a09b8c 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -1560,10 +1560,10 @@ manidx_need(int m) { } } -static void -add_to_index(int level, char *item) +static char * +add_to_index(int level, char *item, char **result) { - char *c = NULL; + char *c = NULL, *out; label[3]++; if (label[3]>'Z') { @@ -1585,11 +1585,15 @@ add_to_index(int level, char *item) } } - scan_troff(item, 1, &c); + out = scan_troff(item, 1, &c); manidx_need(100 + strlen(c)); sprintf(manidx+mip, "
%s
\n", label, c); - if (c) free(c); + if (result) + *result = c; + else + free(c); while (manidx[mip]) mip++; + return out; } static char * @@ -2208,14 +2212,16 @@ scan_request(char *c) { out_html(""); } trans_char(c,'"', '\a'); - add_to_index(mode, c); + h = NULL; + c = add_to_index(mode, c, &h); out_html(" \n

"); else out_html("\"> \n

"); mandoc_synopsis = (strncmp(c, "SYNOPSIS", 8) == 0); - c = (mandoc_command ? scan_troff_mandoc : scan_troff)(c,1,NULL); + out_html(h); + free(h); if (mode) out_html("

\n"); else out_html("\n"); curpos=0; @@ -2232,17 +2238,13 @@ scan_request(char *c) { out_html(change_to_font(0)); out_html(change_to_size(0)); (void) scan_expression(wordlist[0], &i); - add_to_index(i, wordlist[2]); if (mandoc_command) scan_troff_mandoc(wordlist[1],1,&h); else scan_troff(wordlist[1],1,&h); wordlist[1] = h; h = NULL; - if (mandoc_command) - scan_troff_mandoc(wordlist[2],1,&h); - else - scan_troff(wordlist[2],1,&h); + (void) add_to_index(i, wordlist[2], &h); wordlist[2] = h; out_html("