builtin.c: fix build with -Woverlength-strings

C99 only allows string literals long at most 4095 characters.
jq_builtins was a lot longer than that.

I rewrote all the optional libm error stubs in C so the value of
jq_builtins is not build dependent.

I replaced the command that generates builtin.inc with a POSIX compliant
od|sed command that encodes builtin.jq as a comma delimited list of
octal numbers (that can be embedded in C using a {} literal).

I also added -Woverlength-strings to AM_CFLAGS to verify that the
problem is fixed.

Fixes #1481
This commit is contained in:
Emanuele Torre authored and Nico Williams committed 2024-01-26 16:16:25 -06:00
1 parent 7bdc9a7a63
commit 605836b263
2 files changed
+48 -48

No files matched your search

+8 -2
View File
@@ -19,7 +19,8 @@ LIBJQ_SRC = src/builtin.c src/bytecode.c src/compile.c src/execute.c \
### C build options
AM_CFLAGS = -Wextra -Wall -Wno-unused-parameter -Wno-unused-function
AM_CFLAGS = -Wextra -Wall -Wno-unused-parameter -Wno-unused-function \
-Woverlength-strings
if WIN32
AM_CFLAGS += -municode
@@ -119,7 +120,12 @@ src/main.c: src/version.h src/config_opts.inc
src/builtin.inc: $(srcdir)/src/builtin.jq
mkdir -p src
$(AM_V_GEN) sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/\\n"/' $(srcdir)/src/builtin.jq > $@
$(AM_V_GEN) od -v -A n -t o1 -- $< | \
sed -e 's/$$/ /' \
-e 's/\([0123456789]\) /\1, /g' \
-e 's/ $$//' \
-e 's/ 0/ 0/g' \
-e 's/ \([123456789]\)/ 0\1/g' > $@
src/builtin.o: src/builtin.inc
CLEANFILES = src/version.h .remake-version-h src/builtin.inc src/config_opts.inc