launchdarkly / c-client-sdk

LaunchDarkly Client-side SDK for C/C++
Other
7 stars 15 forks source link

Build failed with gcc 11.3 #95

Closed yzabalotski closed 1 year ago

yzabalotski commented 1 year ago

Describe the bug Build failed with gcc 11.3/ubuntu 22.04.

To reproduce

podman run -it --rm ubuntu:22.04 /bin/bash \
-c "apt-get update ; apt-get install -y libcurl-* g++ cmake git ; cd /tmp && git clone --depth 1 --branch 2.5.2 https://github.com/launchdarkly/c-client.git ldclient && cd ldclient && mkdir build && cd build && cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release .. && make -j4"

Expected behavior Build finished successfully.

Logs

[ 24%] Building C object CMakeFiles/ldclientapi.dir/src/event_processor.c.o
/tmp/ldclient/src/client.c: In function 'LDBoolVariationDetail':
/tmp/ldclient/src/client.c:763:41: error: array subscript 'double[0]' is partly outside array bounds of 'LDBoolean[1]' {aka 'char[1]'} [-Werror=array-bounds]
  763 |         **((double **const)destination) = LDGetNumber(source);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/tmp/ldclient/src/client.c:858:25: note: while referencing 'value'
  858 |     LDBoolean           value, *valueRef, fallbackCast;
      |                         ^~~~~
/tmp/ldclient/src/client.c: In function 'LDBoolVariation':
/tmp/ldclient/src/client.c:763:41: error: array subscript 'double[0]' is partly outside array bounds of 'LDBoolean[1]' {aka 'char[1]'} [-Werror=array-bounds]
  763 |         **((double **const)destination) = LDGetNumber(source);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/tmp/ldclient/src/client.c:883:15: note: while referencing 'value'
  883 |     LDBoolean value, *valueRef, fallbackCast;
      |               ^~~~~
[ 26%] Building C object CMakeFiles/ldclientapi.dir/src/flag.c.o
[ 28%] Building C object CMakeFiles/ldclientapi.dir/src/flag_change_listener.c.o
[ 30%] Building C object CMakeFiles/ldclientapi.dir/src/ldnet.c.o
[ 32%] Building C object CMakeFiles/ldclientapi.dir/src/ldthreads.c.o
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/ldclientapi.dir/build.make:188: CMakeFiles/ldclientapi.dir/src/client.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:912: CMakeFiles/ldclientapi.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 34%] Linking CXX static library ../../lib/libgtest.a
[ 34%] Built target gtest
make: *** [Makefile:146: all] Error 2

SDK version 2.5.2 master

Language version, developer tools gcc 11.3

OS/platform Ubuntu 22.04

cwaldren-ld commented 1 year ago

Hi @yzabalotski, thanks so much for the report. We'll investigate.

Filed internally as 179955.

cwaldren-ld commented 1 year ago

This is an interesting one. It looks like GCC 11 introduced a new analysis, and this may be a false positive.

As a workaround while I continue to investigate, I can confirm that the build succeeds with Ubuntu 20.04.

yzabalotski commented 1 year ago

Hi @cwaldren-ld, thank you for the fast response. We spotted the issue because we were trying to move to Ubuntu 22.04. So, any updates so far?

cwaldren-ld commented 1 year ago

Hi @yzabalotski, no updates so far.

To unblock yourself for now, you may modify CMakeLists.txt to remove the -Werror line, which will allow the build to succeed.

cwaldren-ld commented 1 year ago

As would be expected, the issue reproduces with the following Dockerfile as well:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
libcurl-* \
g++ \
cmake \
git

RUN cd /tmp && git clone --depth 1 --branch 2.5.2 https://github.com/launchdarkly/c-client.git ldclient && cd ldclient && mkdir build && cd build && cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release .. && make -j4
cwaldren-ld commented 1 year ago

Hi @yzabalotski, sorry about the long wait on this one. I believe I have a fix, which should go out in the next release.

cwaldren-ld commented 1 year ago

This has been fixed in 2.5.5. Thanks again for your report; please confirm that you no longer encounter the issue.

yzabalotski commented 1 year ago

2.5.5 worked fine, thanks!