jcs
/wikipedia
/amendments
/55
wikipedia: Try resizing buf if we run out of room, don't just dump it
We might be in the middle of a giant infobox or something that isn't
supposed to be printed, so we have to keep growing or die trying.
jcs made amendment 55 about 1 year ago
--- wikipedia.c Mon Oct 30 13:08:05 2023
+++ wikipedia.c Tue Oct 31 11:03:25 2023
@@ -274,7 +274,7 @@ wikipedia_request_process(struct wikipedia_request *wp
struct http_request *req = wpr->http_request;
size_t len, n;
short pct;
- char c, *last;
+ char c, *last, *tbuf;
enum xml_state {
XML_DEFAULT,
XML_IN_NORMALIZED
@@ -633,13 +633,16 @@ get_char:
/* and finally, add the new character */
if (c != 0) {
if (wpr->buf_idx >= wpr->buf_size) {
- if (!browser_print(wpr->browser, wpr->buf, wpr->buf_idx,
- wpr->style)) {
+ tbuf = wpr->buf;
+ wpr->buf = xrealloc(wpr->buf, wpr->buf_size * 2);
+ if (wpr->buf == NULL) {
+ wpr->buf = tbuf;
+ warn("Failed resizing parse buffer to %ld bytes, "
+ "not enough memory", wpr->buf_size * 2);
wpr->state = WP_STATE_DONE;
goto done_parsing;
}
- wpr->article_len += wpr->buf_idx;
- wpr->buf_idx = 0;
+ wpr->buf_size *= 2;
}
wpr->buf[wpr->buf_idx++] = c;
}