X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/7516ec539764125f657a144cce32ce96df05bcf4..0a1c8a90e23304220f6602e98aba5f891a1350b2:/t/rendertest.c diff --git a/t/rendertest.c b/t/rendertest.c index 14faafb..00e0c59 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,12 @@ #include #include -#include +#include "cdecl.h" + +#define PROGNAME "rendertest" #include "test.h" +#include "getline.h" -#define PROGNAME "outbuf" -static const char *progname = PROGNAME; static const char sopts[] = "n:ECVH"; static const struct option lopts[] = { { "count", 1, NULL, 'n' }, @@ -63,9 +64,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 +76,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; } @@ -109,9 +109,8 @@ int main(int argc, char **argv) mode = MODE_ENGLISH; break; case 'n': - if (!strict_strtoul(&n, optarg, 0) || n > (size_t)-2) { - fprintf(stderr, "%s: invalid count: %s\n", - progname, optarg); + if (!test_strtoul(&n, optarg) || n > (size_t)-2) { + print_error("invalid count: %s", optarg); return EXIT_FAILURE; } break; @@ -127,12 +126,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 (do_getline(&line, &sz)) { if (do_test(line, n, mode) < 0) ret = EXIT_FAILURE; }