--- /home/bob/code/csvutils_CLONE/src/csvcheck.c 2016-12-18 18:46:19.810786627 +0100 +++ /home/bob/csvutils-master/src/csvcheck.c 2016-12-19 10:36:27.409339363 +0100 @@ -98,6 +98,7 @@ FILE *fp; size_t bytes_read; size_t retval; + int ok = 1; if (csv_init(&p, CSV_STRICT|CSV_STRICT_FINI) != 0) { fprintf(stderr, "Failed to initialize csv parser\n"); @@ -119,23 +120,27 @@ while ((bytes_read=fread(buf, 1, 1024, fp)) > 0) { if ((retval = csv_parse(&p, buf, bytes_read, NULL, NULL, NULL)) != bytes_read) { + ok = 0; if (csv_error(&p) == CSV_EPARSE) { printf("%s: malformed at byte %lu\n", filename ? filename : "stdin", (unsigned long)pos + retval + 1); - goto end; + // goto end; } else { printf("Error while processing %s: %s\n", filename ? filename : "stdin", csv_strerror(csv_error(&p))); - goto end; + // goto end; } + break; } pos += 1024; } - if (csv_fini(&p, NULL, NULL, NULL) != 0) - printf("%s: missing closing quote at end of input\n", filename ? filename : "stdin"); - else - printf("%s well-formed\n", filename ? filename : "data is"); + if (ok) { + if (csv_fini(&p, NULL, NULL, NULL) != 0) + printf("%s: missing closing quote at end of input\n", filename ? filename : "stdin"); + else + printf("%s well-formed\n", filename ? filename : "data is"); + } - end: + csv_free(&p); fclose(fp); }