From fa0dbc76ee9459e3faecdce00b888ae479fd01d4 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 22 Sep 2023 14:48:04 +0200 Subject: [PATCH] Fudge code to get rid of warnings from GCC GCC is generating some spurious warnings: * The OSMObject::user() functions returns a pointer outside the OSMObject. That's okay, because we know we put the data there, but GCC thinks this is fishy. We can not disable the stringop-overread warning inside the library, because it is only produced in the users code. But the magic [[gnu::noipa]]attribute stops GCC from looking through the user() call and the warning doesn't happen. Because older GCCs and other compilers don't understand the attribute, we have to check for the compiler version. * The Tag::after_null() call similarly triggers an array-bounds warning, which the changes code doesn't for some reason. --- .github/workflows/ci.yml | 12 +----------- include/osmium/memory/buffer.hpp | 3 +++ include/osmium/osm/object.hpp | 3 +++ include/osmium/osm/tag.hpp | 8 ++++++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95469979..a44ed622 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,6 @@ jobs: # Uses gcc 12.2.0, clang 15.0.7, cmake 3.24.2 image: "ubuntu:22.04" ubuntu: 22 - CXXFLAGS: -Wno-stringop-overread - name: Debian-10 # Uses gcc 8.3.0, clang 7.0.1, cmake 3.13.4 image: "debian:buster" @@ -65,15 +64,12 @@ jobs: - name: Debian-12 # Uses gcc 12.2.0, clang 15.0.6, cmake 3.25.1 image: "debian:bookworm" - CXXFLAGS: -Wno-stringop-overread - name: Debian-12 image: "debian:bookworm" cpp_version: c++17 - CXXFLAGS: -Wno-stringop-overread - name: Debian-12 image: "debian:bookworm" cpp_version: c++20 - CXXFLAGS: -Wno-stringop-overread - name: Debian-12 image: "debian:bookworm" c_compiler: clang @@ -91,7 +87,6 @@ jobs: - name: Debian-12 image: "debian:bookworm" build_type: RelWithDebInfo - CXXFLAGS: -Wno-stringop-overread - name: Debian-12 image: "debian:bookworm" c_compiler: clang @@ -100,14 +95,12 @@ jobs: LDFLAGS: -fsanitize=address,undefined - name: Debian-Testing image: "debian:testing" - CXXFLAGS: -Wno-stringop-overread -Wno-dangling-reference - name: Debian-Testing image: "debian:testing" c_compiler: clang cpp_compiler: clang++ - name: Debian-Experimental image: "debian:experimental" - CXXFLAGS: -Wno-stringop-overread -Wno-dangling-reference - name: Debian-Experimental image: "debian:experimental" c_compiler: clang @@ -115,19 +108,16 @@ jobs: - name: Fedora-35 # Uses gcc 11.2.1, clang 12.0.1, cmake 3.20.5 image: "fedora:35" - CXXFLAGS: -Wno-stringop-overread - name: Fedora-36 # Uses gcc 12.2.0, clang 14.0.5, cmake 3.24.2 image: "fedora:36" - CXXFLAGS: -Wno-stringop-overread - name: Fedora-37 # Uses gcc 12.3.1, clang 15.0.7, cmake 3.26.4 image: "fedora:37" - CXXFLAGS: -Wno-stringop-overread - name: Fedora-38 # Uses gcc 13.0.1, clang 16.0.5, cmake 3.26.4 image: "fedora:38" - CXXFLAGS: -Wno-stringop-overread -Wno-dangling-reference + CXXFLAGS: -Wno-dangling-reference container: image: ${{ matrix.image }} env: diff --git a/include/osmium/memory/buffer.hpp b/include/osmium/memory/buffer.hpp index e51f5deb..1b44ad4c 100644 --- a/include/osmium/memory/buffer.hpp +++ b/include/osmium/memory/buffer.hpp @@ -480,6 +480,9 @@ namespace osmium { * buffer. */ template +#if defined(__GNUC__) && (__GNUC__ > 11) + [[gnu::noipa]] // avoids dangling-reference warning from GNU compiler +#endif T& get(const std::size_t offset) const { assert(m_data && "This must be a valid buffer"); assert(offset % alignof(T) == 0 && "Wrong alignment"); diff --git a/include/osmium/osm/object.hpp b/include/osmium/osm/object.hpp index a62c7603..530fffd7 100644 --- a/include/osmium/osm/object.hpp +++ b/include/osmium/osm/object.hpp @@ -316,6 +316,9 @@ namespace osmium { } /// Get user name for this object. +#if defined(__GNUC__) && (__GNUC__ > 11) + [[gnu::noipa]] // avoids stringop-overread warning from GNU compiler +#endif const char* user() const noexcept { return reinterpret_cast(data() + sizeof_object()); } diff --git a/include/osmium/osm/tag.hpp b/include/osmium/osm/tag.hpp index ac2d0f0c..7dd335d5 100644 --- a/include/osmium/osm/tag.hpp +++ b/include/osmium/osm/tag.hpp @@ -51,11 +51,15 @@ namespace osmium { friend class osmium::memory::CollectionIterator; static unsigned char* after_null(unsigned char* ptr) noexcept { - return reinterpret_cast(std::strchr(reinterpret_cast(ptr), 0) + 1); + while (*ptr) { ++ptr; } + ++ptr; + return ptr; } static const unsigned char* after_null(const unsigned char* ptr) noexcept { - return reinterpret_cast(std::strchr(reinterpret_cast(ptr), 0) + 1); + while (*ptr) { ++ptr; } + ++ptr; + return ptr; } unsigned char* next() noexcept {