Skip to content
Myr

Fix compiler warning `type-limits` in `found_string` (ref #2911) (#3263)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Whether `char` has a sign is implementation dependent, and `c >= 0` may result in a compiler warning. We can use bitwise operator to check whether the character is a control character, regardless of the sign.

authored by itchyny · committed by GitHub · parent 6d8e9f9 · Browse files · 2 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−1 removed

  • tests:+14 added−0 removed
  • other:+1 added−1 removed

2 files+15 added−1 removed

modified:src/jv_parse.c+1 added-1 removed
491 unmodified lines
492 default:493 return "Invalid escape";494 }495 } else {496 if (c >= 0 && c <= 0x001f)496 if (!(c & ~0x1F))497 return "Invalid string: control characters from U+0000 through U+001F must be escaped";498 *out++ = c;499 }500 }
413 unmodified lines
modified:tests/shtest+14 added
92 unmodified lines
93 exit 294fi95cmp $d/out $d/expected9697# Test control characters for #290998cat > $d/expected <<EOF99jq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 1, column 3100EOF101for i in 1 2 30 31; do102 if printf "\"$(printf '\\%03o' $i)\"" | $JQ '.' > $d/out 2>&1; then103 printf 'Error expected but jq exited successfully\n' 1>&2104 exit 2105 fi106 cmp $d/out $d/expected107done108printf '" ~\\u007f"\n' > $d/expected109printf "\"$(printf '\\%03o' 32 126 127)\"" | $JQ '.' > $d/out 2>&1110cmp $d/out $d/expected111112## Test --exit-status113data='{"i": 1}\n{"i": 2}\n{"i": 3}\n'114printf "$data" | $JQ --exit-status 'select(.i==1)' > /dev/null 2>&1
619 unmodified lines