Skip to content

Commit

Permalink
Fudge code to get rid of warnings from GCC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joto committed Sep 22, 2023
1 parent cd892f9 commit fa0dbc7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -100,34 +95,29 @@ 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
cpp_compiler: clang++
- 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:
Expand Down
3 changes: 3 additions & 0 deletions include/osmium/memory/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ namespace osmium {
* buffer.
*/
template <typename T>
#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");
Expand Down
3 changes: 3 additions & 0 deletions include/osmium/osm/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>(data() + sizeof_object());
}
Expand Down
8 changes: 6 additions & 2 deletions include/osmium/osm/tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ namespace osmium {
friend class osmium::memory::CollectionIterator;

static unsigned char* after_null(unsigned char* ptr) noexcept {
return reinterpret_cast<unsigned char*>(std::strchr(reinterpret_cast<char*>(ptr), 0) + 1);
while (*ptr) { ++ptr; }
++ptr;
return ptr;
}

static const unsigned char* after_null(const unsigned char* ptr) noexcept {
return reinterpret_cast<const unsigned char*>(std::strchr(reinterpret_cast<const char*>(ptr), 0) + 1);
while (*ptr) { ++ptr; }
++ptr;
return ptr;
}

unsigned char* next() noexcept {
Expand Down

0 comments on commit fa0dbc7

Please sign in to comment.