You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 15, 2023. It is now read-only.
The following program takes O(n^2) time (but not memory) for very large arguments. I suspect one needs #392 applied to notice (otherwise, one hits a stack overflow first).
#include<ctype.h>#include<gumbo.h>#include<stdint.h>#include<limits.h>#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(intargc, char**argv) {
if (argc!=2) {
fputs("Must have exactly one argument: depth of tree to make\n", stderr);
return1;
}
char*endp;
unsigned long longq=strtoull(argv[1], &endp, 0);
constsize_tmaxarg= (SIZE_MAX-9) / sizeof"<i>";
if (q>maxarg) {
fprintf(stderr, "Argument too large! Must be at or below %zu\n", maxarg);
exit(1);
}
if (*endp) {
fprintf(stderr, "Trailing junk at end of argument!\n");
exit(1);
}
char*buf=malloc(q* (2*sizeof"<i>"-1) +sizeof"<i>\n");
if (!buf) {
fputs("Out of mem allocating buffer!\n", stderr);
return1;
}
char*bufptr=buf;
memcpy(bufptr, "<i>\n", 4);
bufptr+=4;
for (size_ti=0; i<q; ++i) {
memcpy(bufptr, "<i>", 3);
bufptr+=3;
}
for (size_ti=0; i<q; ++i) {
memcpy(bufptr, "</i>", 3);
bufptr+=4;
}
GumboOptionsoptions;
memcpy(&options, &kGumboDefaultOptions, sizeofoptions);
options.max_errors=50;
GumboOutput*output=gumbo_parse_with_options(&options, buf, strlen(buf));
if (!output) {
fputs("Out of mem while parsing!\n", stderr);
free(buf);
return1;
}
gumbo_destroy_output(&kGumboDefaultOptions, output);
free(buf);
return0;
}
perf reveals that the time is spent in reconstruct_active_formatting_elements.