danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
715 stars 163 forks source link

Unable to compile Release 0.171.0 with gcc (GCC) 13.1.1 #436

Closed eitlane closed 1 year ago

eitlane commented 1 year ago

Hello all,

I am unable to compile Release 0.171.0 with gcc (GCC) 13.1.1. Here is the output:

[ 84%] Building CXX object test/CMakeFiles/unit_tests.dir/corelib/src/jsoncons_tests.cpp.o
In file included from /work/jsoncons-0.171.0/include/jsoncons/json_encoder.hpp:20,
                 from /work/jsoncons-0.171.0/include/jsoncons/pretty_print.hpp:19,
                 from /work/jsoncons-0.171.0/include/jsoncons/basic_json.hpp:29,
                 from /work/jsoncons-0.171.0/include/jsoncons/json.hpp:10,
                 from /work/jsoncons-0.171.0/test/corelib/src/json_type_traits_chrono_tests.cpp:5:
In member function ‘void jsoncons::basic_bigint<Allocator>::resize(size_type) [with Allocator = std::allocator<unsigned char>]’,
    inlined from ‘jsoncons::basic_bigint<Allocator>& jsoncons::basic_bigint<Allocator>::operator>>=(uint64_t) [with Allocator = std::allocator<unsigned char>]’ at /work/jsoncons-0.171.0/include/jsoncons/bigint.hpp:771:19,
    inlined from ‘void jsoncons::basic_bigint<Allocator>::unnormalize(jsoncons::basic_bigint<Allocator>&, int, int) const [with Allocator = std::allocator<unsigned char>]’ at /work/jsoncons-0.171.0/include/jsoncons/bigint.hpp:1559:17,
    inlined from ‘void jsoncons::basic_bigint<Allocator>::divide(jsoncons::basic_bigint<Allocator>, jsoncons::basic_bigint<Allocator>&, jsoncons::basic_bigint<Allocator>&, bool) const [with Allocator = std::allocator<unsigned char>]’ at /work/jsoncons-0.171.0/include/jsoncons/bigint.hpp:1423:24:
/work/jsoncons-0.171.0/include/jsoncons/bigint.hpp:514:19: error: ‘void* memset(void*, int, size_t)’ specified bound between 18446744073441116168 and 18446744073709551608 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
  514 |             memset( data()+len_old, 0, (common_stor_.length_ - len_old)*sizeof(uint64_t) );
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 85%] Building CXX object test/CMakeFiles/unit_tests.dir/corelib/src/JSONTestSuite_tests.cpp.o
[ 86%] Building CXX object test/CMakeFiles/unit_tests.dir/corelib/src/ojson_tests.cpp.o
cc1plus: all warnings being treated as errors
gmake[2]: *** [test/CMakeFiles/unit_tests.dir/build.make:1420: test/CMakeFiles/unit_tests.dir/corelib/src/json_type_traits_chrono_tests.cpp.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
gmake[1]: *** [CMakeFiles/Makefile2:854: test/CMakeFiles/unit_tests.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
[root@a860fea463db _build]# gcc --version
gcc (GCC) 13.1.1 20230614 (Red Hat 13.1.1-4)

Easiest way to reproduce is Fedora 38 docker container (with installed gcc and cmake) 1) Extract v0.171.0.tar.gz 2) In jsoncons-0.171.0 create a folder _build 3) Enter _build 4) cmake .. -DJSONCONS_BUILD_TESTS=On 5) cmake --build .

Thanks, Venci

danielaparker commented 1 year ago

Expected integer values to be passed to resize would be 2, 3, 4. It's certainly true that if a value of 18446744073709551608 were passed, there would be an issue. I suppose we could have an assert if the value exceeded, say, 8.

danielaparker commented 1 year ago

Fixed on master