[PostGIS] #6153: warning: array subscript has type 'char' [-Wchar-subscripts] in liblwgeom
PostGIS
trac at osgeo.org
Thu Oct 29 04:07:11 PDT 2026
#6153: warning: array subscript has type 'char' [-Wchar-subscripts] in liblwgeom
---------------------+---------------------------
Reporter: robe | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.7.1
Component: postgis | Version: 3.6.x
Keywords: |
---------------------+---------------------------
Per https://lists.osgeo.org/pipermail/postgis-
users/2026-October/047099.html
{{{
>> There is a large amount of ctype UB. I don't know if this is new, but
I think I
>> would have noticed and said something.
>>
>> Briefly, ctype functions take an int, and are defined only for values
that are
>> valid for unsigned char or EOF. Everything else is UB.
>> Calling them with a variable of type char, if char is signed, leads to
negative
>> values. I would expect at least some systems in CI to warn somehow,
but
>> maybe they don't.
>>
>> libtool: compile: gcc -I../../liblwgeom/../deps/ryu/..
-I/usr/pkg/include -
>> I/usr/pkg/include -I/usr/pkg/include -I/usr/pkg/include/libxml2 -
>> I/usr/pkg/include -I/usr/pkg/include -I/usr/pkg/include/json-c -DNDEBUG
-I.
>> -I../../liblwgeom -std=gnu11 -g -O2 -fno-math-errno -fno-signed-zeros
-Wall -
>> O2 -fPIC -DPIC -c ../../liblwgeom/optionlist.c -fPIC -DPIC -o
.libs/optionlist.o
>> In file included from /usr/include/ctype.h:100,
>> from ../../liblwgeom/optionlist.c:28:
>> ../../liblwgeom/optionlist.c: In function
'option_list_string_to_lower':
>> ../../liblwgeom/optionlist.c:36:32: warning: array subscript has type
'char' [-
>> Wchar-subscripts]
>> 36 | *key = tolower(*key);
>> | ^
>
}}}
I researched this issue and it seems this has existed for quite sometime
in our code possibly since 3.2.0 and there is more than this location to
fix.
I guess one reason only NetBSD has this warning turned on by default is
why none of our other CIS are testing for it. Also in glibc compile it
seems plain char is by default unsigned so it could never trigger this. I
fussed around adding -Wchar-subscripts -Werror=char-subscripts to
configure on GHA cis and couldn't get them to fail. Suggestion from AI is
to use NetBSD or Alpine or force GCC.
So even though this is an issue, for most OS its already prevented. Can't
be triggered in glibc. MingW and windows in theory can in test mode but
production builds skip over it.
Still worth fixing but not for 3.7.0 in case we make a mistake. I'll
create a fix in master and maybe put in 3.7.1 but will keep this open
until after we have released 3.7.0
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/6153>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list