Skip to content

Commit f983703

Browse files
committed
A more robust testing program.
1 parent f08920f commit f983703

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

tests/stringparsingcheck.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ static bool parse_string(const char *p, char *output, char **end) {
200200
}
201201
}
202202
// end of borrowed code
203+
char * bigbuffer; // global variable
203204

204205
inline void foundBadString(const u8 *buf) {
205206
bad_string++;
206207
char *end;
207-
char bigbuffer[4096]; // if some strings exceeds 4k, this will fail!
208208
if (parse_string((const char *)buf, bigbuffer, &end)) {
209209
printf("WARNING: Sajson-like parser seems to think that the string is "
210210
"valid %32s \n",
@@ -231,7 +231,6 @@ inline void foundString(const u8 *buf, const u8 *parsed_begin,
231231
total_string_length += thislen;
232232
good_string++;
233233
char *end = NULL;
234-
char bigbuffer[4096]; // if some strings exceeds 4k, this will fail!
235234
if (!parse_string((const char *)buf, bigbuffer, &end)) {
236235
printf("WARNING: reference parser seems to think that the string is NOT "
237236
"valid %32s \n",
@@ -338,11 +337,18 @@ bool validate(const char *dirname) {
338337
std::cerr << "can't allocate memory" << std::endl;
339338
return false;
340339
}
340+
bigbuffer = (char *) malloc(p.size());
341+
if(bigbuffer == NULL) {
342+
std::cerr << "can't allocate memory" << std::endl;
343+
free((void*)p.data());
344+
return false;
345+
}
341346
bad_string = 0;
342347
good_string = 0;
343348
total_string_length = 0;
344349
empty_string = 0;
345350
bool isok = json_parse(p, pj);
351+
free(bigbuffer);
346352
free((void*)p.data());
347353
if (good_string > 0) {
348354
printf("File %40s %s --- bad strings: %10zu \tgood strings: %10zu\t "

0 commit comments

Comments
 (0)