--raw-input ought to read NULs (partial fix #760)

We can't know how many bytes fgets() read when we reach EOF and fgets()
didn't see a newline; we can only assume that at least strlen(buf) bytes
were read.  This is quite obnoxious if one wants to use NULs in raw
input, but at least we can make reading "a\0b\0c\0" with no newline
yield "a\0b\0c", losing only the final sequence of NULs.

We can't use getline() either, since it will want to allocate a buffer
big enough for an entire line, and we might not have any newlines in our
input.  A complete fix will have to use getc() or read(), preferably the
latter.
This commit is contained in:
Nicolas Williams committed 2015-04-23 23:43:44 -05:00
1 parent 7d938487dd
commit dad6e42934
3 files changed
+56 -22

No files matched your search

+5 -2
View File
@@ -12,10 +12,9 @@ fi
mods=$PWD/tests/modules
# jq-coded tests here:
cat $@ | $VALGRIND $Q ./jq -L "$mods" --run-tests
set -x
clean=true
d=
clean () {
@@ -32,6 +31,10 @@ if [ -z "$d" ]; then
exit 0
fi
printf 'a\0b\nc\0d\ne' > $d/input
$VALGRIND $Q ./jq -Rse '. == "a\u0000b\nc\u0000d\ne"' $d/input
$VALGRIND $Q ./jq -Rne '[inputs] == ["a\u0000b", "c\u0000d", "e"]' $d/input
## Test constant folding
## XXX If we add a builtin to list the program's disassembly then we can