From baa7006e639c232622246414fe35388a0c209f34 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Fri, 10 Dec 2021 01:25:04 +0100 Subject: [PATCH] ci: enable warnings as errors --- .github/workflows/android.yml | 51 ++++++++++++++++++++--------------- .github/workflows/linux.yml | 7 +++++ .github/workflows/macos.yml | 5 ---- .github/workflows/windows.yml | 7 ++++- src/symbolize.cc | 25 ++++------------- 5 files changed, 47 insertions(+), 48 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 6bd01fcae..859824e03 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -17,28 +17,35 @@ jobs: build_type: [Debug, Release] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Setup Ninja - uses: ashutoshvarma/setup-ninja@master - with: - version: 1.10.0 + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + with: + version: 1.10.0 - - name: Configure - run: | - cmake -S . -B build_${{matrix.abi}} \ - -DANDROID_ABI=${{matrix.abi}} \ - -DANDROID_NATIVE_API_LEVEL=28 \ - -DANDROID_STL=c++_shared \ - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ - -DCMAKE_CXX_EXTENSIONS=OFF \ - -DCMAKE_CXX_STANDARD=${{matrix.std}} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ - -G Ninja \ - -Werror + - name: Setup C++98 Environment + if: matrix.std == '98' + run: | + echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV - - name: Build - run: | - cmake --build build_${{matrix.abi}} \ - --config ${{matrix.build_type}} + - name: Configure + env: + CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}} + run: | + cmake -S . -B build_${{matrix.abi}} \ + -DANDROID_ABI=${{matrix.abi}} \ + -DANDROID_NATIVE_API_LEVEL=28 \ + -DANDROID_STL=c++_shared \ + -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ + -DCMAKE_CXX_EXTENSIONS=OFF \ + -DCMAKE_CXX_STANDARD=${{matrix.std}} \ + -DCMAKE_CXX_STANDARD_REQUIRED=ON \ + -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ + -G Ninja \ + -Werror + + - name: Build + run: | + cmake --build build_${{matrix.abi}} \ + --config ${{matrix.build_type}} diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 71e71117e..fe0b07a96 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -60,7 +60,14 @@ jobs: echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV echo 'GTest_ROOT=${{github.workspace}}/gtest' >> $GITHUB_ENV + - name: Setup C++98 Environment + if: matrix.std == '98' + run: | + echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV + - name: Configure + env: + CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}} run: | cmake -S . -B build_${{matrix.build_type}} \ -DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \ diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index fbda89572..be09b97ba 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -31,11 +31,6 @@ jobs: run: | echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV - - name: Setup C++98 Environment - if: matrix.std == '98' - run: | - echo 'CXXFLAGS=-Wall -Wextra -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}}' >> $GITHUB_ENV - - name: Configure shell: bash env: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 14245f6c6..0961da4c2 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -100,9 +100,14 @@ jobs: mingw-w64-${{matrix.env}}-gflags mingw-w64-${{matrix.env}}-ninja + - name: Setup C++98 Environment + if: matrix.std == '98' + run: | + echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV + - name: Configure env: - CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Werror -Wno-error=variadic-macros -Wno-error=long-long + CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}} run: | if [[ ${{matrix.build_type}} == "Debug" ]]; then export CXXFLAGS="--coverage ${CXXFLAGS}" diff --git a/src/symbolize.cc b/src/symbolize.cc index 6b9df1cf2..2ca84c96f 100644 --- a/src/symbolize.cc +++ b/src/symbolize.cc @@ -666,12 +666,12 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, // POSIX doesn't define any async-signal safe function for converting // an integer to ASCII. We'll have to define our own version. -// itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the +// itoa_r() converts an (unsigned) integer to ASCII. It returns "buf", if the // conversion was successful or NULL otherwise. It never writes more than "sz" // bytes. Output will be truncated as needed, and a NUL character is always // appended. // NOTE: code from sandbox/linux/seccomp-bpf/demo.cc. -static char *itoa_r(intptr_t i, char *buf, size_t sz, unsigned base, size_t padding) { +static char *itoa_r(uintptr_t i, char *buf, size_t sz, unsigned base, size_t padding) { // Make sure we can write at least one NUL byte. size_t n = 1; if (n > sz) @@ -684,21 +684,6 @@ static char *itoa_r(intptr_t i, char *buf, size_t sz, unsigned base, size_t padd char *start = buf; - uintptr_t j = static_cast(i); - - // Handle negative numbers (only for base 10). - if (i < 0 && base == 10) { - // This does "j = -i" while avoiding integer overflow. - j = static_cast(-(i + 1)) + 1; - - // Make sure we can write the '-' character. - if (++n > sz) { - buf[0] = '\000'; - return NULL; - } - *start++ = '-'; - } - // Loop until we have converted the entire number. Output at least one // character (i.e. '0'). char *ptr = start; @@ -710,12 +695,12 @@ static char *itoa_r(intptr_t i, char *buf, size_t sz, unsigned base, size_t padd } // Output the next digit. - *ptr++ = "0123456789abcdef"[j % base]; - j /= base; + *ptr++ = "0123456789abcdef"[i % base]; + i /= base; if (padding > 0) padding--; - } while (j > 0 || padding > 0); + } while (i > 0 || padding > 0); // Terminate the output with a NUL character. *ptr = '\000';