vincentlaucsb / csv-parser

A high-performance, fully-featured CSV parser and serializer for modern C++.
MIT License
864 stars 144 forks source link

compilation warnings(array-bounds) using GCC13 on Ubuntu 22.04 with -O3 -std=c++20 #231

Closed sangoblin closed 1 month ago

sangoblin commented 1 month ago

In file included from /opt/GCC/v13.3.0/include/c++/13/algorithm:60, from /opt/csv-parser/v2.2.3/include/csv.hpp:37,
In static member function 'static constexpr _Up std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp, _Tp, _Up) [with _Tp = const char; _Up = char; bool _IsMove = false]', inlined from 'constexpr _OI std::copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const char; _OI = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_algobase.h:506:30, inlined from 'constexpr _OI std::copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const char; _OI = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_algobase.h:533:42, inlined from 'constexpr _OI std::copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::normal_iterator<const char, vector >; _OI = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_algobase.h:540:31, inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II = gnu_cxx::normal_iterator<const char, vector >; _OI = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_algobase.h:633:7, inlined from 'static _ForwardIterator std::uninitialized_copy::uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = gnu_cxx::__normal_iterator<const char, std::vector >; _ForwardIterator = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_uninitialized.h:147:27, inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = gnu_cxx::normal_iterator<const char, vector >; _ForwardIterator = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_uninitialized.h:185:15, inlined from 'constexpr _ForwardIterator std::uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = gnu_cxx::normal_iterator<const char, vector >; _ForwardIterator = char; _Tp = char]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_uninitialized.h:373:37, inlined from 'constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = char; _Alloc = std::allocator]' at /opt/GCC/v13.3.0/include/c++/13/bits/stl_vector.h:606:31, inlined from 'constexpr csv::CSVFormat::CSVFormat(const csv::CSVFormat&)' at /opt/csv-parser/v2.2.3/include/csv.hpp:4917:11, inlined from 'csv::CSVGuessResult csv::internals::_guess_format(csv::string_view, const std::vector&)' at /opt/csv-parser/v2.2.3/include/csv.hpp:7417:46, inlined from 'csv::CSVReader::CSVReader(csv::string_view, csv::CSVFormat)' at /opt/csv-parser/v2.2.3/include/csv.hpp:7471:57: /opt/GCC/v13.3.0/include/c++/13/bits/stl_algobase.h:437:30: warning: 'void* builtin_memcpy(void, const void, long unsigned int)' forming offset 1 is out of the bounds [0, 1] [-Warray-bounds=] 437 | builtin_memmove(result, first, sizeof(_Tp) * _Num); | ~~~^~~~~~~~~

vincentlaucsb commented 1 month ago

I'm not exactly seeing what I can fix on my end.

It seems like an issue with the C++ STL that GCC uses, specifically with their implementation of std::vector.

The _guess_format() method does not construct any vectors, it merely accepts a vector<char> as a const reference.

From there, the CSV library performs a basic loop over the contents of the vector using the built-in iterator. There's nothing wrong or unsafe about this code.

image

It seems the compiler is unhappy with the implementation of the std::vector::iterator because of a potentially unsafe operation in __builtin_memcpy, which again, is not fixable on my end.