X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fhtml2html.c;h=903e9696152cb7b5b8a235770246337948111381;hb=44ce30085f81c675f9328effb744e9eb3c239c8f;hp=4ac9a8fec9ecc9afc0ae9639dabd836c734e6b03;hpb=2add3d7e0100be263626bf60a9aa16cf77a0782d;p=citadel.git diff --git a/webcit/html2html.c b/webcit/html2html.c index 4ac9a8fec..903e96961 100644 --- a/webcit/html2html.c +++ b/webcit/html2html.c @@ -37,31 +37,38 @@ void output_html(void) { char *ptr; char *msgstart; char *msgend; - int total_length = 1; + int buffer_length = 1; int line_length = 0; + int content_length = 0; msg = strdup(""); - msgstart = msg; - msgend = msg; while (serv_gets(buf), strcmp(buf, "000")) { line_length = strlen(buf); - total_length = total_length + line_length + 1; - msg = realloc(msg, total_length + 1); - strcpy(msgend, buf); - msgend[line_length++] = '\n' ; - msgend[line_length] = 0; - msgend = &msgend[line_length]; + buffer_length = content_length + line_length + 2; + msg = realloc(msg, buffer_length); + if (msg == NULL) { + wprintf("realloc() error! " + "couldn't get %d bytes: %s

\n", + buffer_length + 1, + strerror(errno)); + return; + } + strcpy(&msg[content_length], buf); + content_length += line_length; + strcpy(&msg[content_length], "\n"); + content_length += 1; } ptr = msg; msgstart = msg; - /* msgend is already set correctly */ + msgend = &msg[content_length]; while (ptr < msgend) { /* Advance to next tag */ ptr = strchr(ptr, '<'); + if ((ptr == NULL) || (ptr >= msgend)) break; ++ptr; if ((ptr == NULL) || (ptr >= msgend)) break; @@ -100,5 +107,6 @@ void output_html(void) { /* Now give back the memory */ free(msg); + }