Prevent CRLF conversion of inputs in json_parser test module
authorAndrew Dunstan <[email protected]>
Tue, 9 Jul 2024 21:29:48 +0000 (17:29 -0400)
committerAndrew Dunstan <[email protected]>
Tue, 9 Jul 2024 21:29:48 +0000 (17:29 -0400)
Do this by opening the file in PG_BINARY_R mode. This prevents us from
getting wrong byte count from stat().

Per complaint from Andres Freund

Discussion: https://postgr.es/m/20240707052030[email protected]

Backpatch to rlease 17 where this code was introduced

src/test/modules/test_json_parser/test_json_parser_incremental.c
src/test/modules/test_json_parser/test_json_parser_perf.c

index f4c442ac3652811c9456e809e44c0ef59cbbb3fd..47040e1e4217d03487b3d86201c2a6c39785b6df 100644 (file)
@@ -124,7 +124,7 @@ main(int argc, char **argv)
    makeJsonLexContextIncremental(&lex, PG_UTF8, need_strings);
    initStringInfo(&json);
 
-   if ((json_file = fopen(testfile, "r")) == NULL)
+   if ((json_file = fopen(testfile, PG_BINARY_R)) == NULL)
        pg_fatal("error opening input: %m");
 
    if (fstat(fileno(json_file), &statbuf) != 0)
index ea85626cbd8f49e962e3e2b8d601e22c1c456972..74cc5f3f5487582e542f633d838383c3696be86a 100644 (file)
@@ -55,7 +55,7 @@ main(int argc, char **argv)
 
    sscanf(argv[1], "%d", &iter);
 
-   if ((json_file = fopen(argv[2], "r")) == NULL)
+   if ((json_file = fopen(argv[2], PG_BINARY_R)) == NULL)
        pg_fatal("Could not open input file '%s': %m", argv[2]);
 
    while ((n_read = fread(buff, 1, 6000, json_file)) > 0)