X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/d546887cd6d807f258fc4fb2f47a655310e356ba..481f693b0400b05586d90f60494e0e661ad8a1c1:/t/rendertest.c diff --git a/t/rendertest.c b/t/rendertest.c index 42a2c5e..e64526f 100644 --- a/t/rendertest.c +++ b/t/rendertest.c @@ -1,6 +1,6 @@ /* * Helper to verify the output rendering routines. - * Copyright © 2023 Nick Bowler + * Copyright © 2023-2024 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,11 +23,11 @@ #include #include -#include -#include "test.h" +#include "cdecl.h" #define PROGNAME "rendertest" -static const char *progname = PROGNAME; +#include "test.h" + static const char sopts[] = "n:ECVH"; static const struct option lopts[] = { { "count", 1, NULL, 'n' }, @@ -63,9 +63,8 @@ static int do_test(char *line, unsigned long n, int mode) decl = cdecl_parse_decl(line); if (!decl) { - fprintf(stderr, "%s: %s\n", progname, cdecl_get_error()->str); - fprintf(stderr, "%s: the failed input was: %s\n", - progname, line); + print_error("%s", cdecl_get_error()->str); + print_error("the failed input was: %s", line); return -1; } @@ -76,12 +75,12 @@ static int do_test(char *line, unsigned long n, int mode) rc = cdecl_declare(line, n, decl); if (n && ( rc < n ? line[rc] : line[n-1] ) != '\0') { - fprintf(stderr, "%s: output is not 0-terminated\n", progname); + print_error("output is not 0-terminated"); return -1; } if (line[n] != '\a') { - fprintf(stderr, "%s: output overflow\n", progname); + print_error("output overflow"); return -1; } @@ -110,8 +109,7 @@ int main(int argc, char **argv) break; case 'n': if (!test_strtoul(&n, optarg) || n > (size_t)-2) { - fprintf(stderr, "%s: invalid count: %s\n", - progname, optarg); + print_error("invalid count: %s", optarg); return EXIT_FAILURE; } break; @@ -127,12 +125,12 @@ int main(int argc, char **argv) } } - line = malloc_nofail((sz = n+1)); - while (getline(&line, &sz, stdin) >= 0) { - char *c = strchr(line, '\n'); - if (c) - *c = '\0'; - + /* + * Ensure the preallocated buffer is more than one byte, otherwise we + * will hit a bug in AIX 7.2 getline and fall into an infinite loop. + */ + line = malloc_nofail((sz = MAX(n+1, 10))); + while (test_getline(&line, &sz)) { if (do_test(line, n, mode) < 0) ret = EXIT_FAILURE; }