Bump clang-format and clang-tidy for linux pipeline

Use version 20 which is the current latest.

Fix bug clang-tidy found if reading the save file fails.
Format code per clang-format-20

I surpressed all new warnings in clang-tidy but we will probably want to
enable and fix some of them.

run-clang-tidy is used instead of calling clang-tidy directly in order
to automatically pull all source files.
This commit is contained in:
Stephen E. Baker
2025-05-08 12:26:41 -04:00
parent f70b21e157
commit e3c7ea7ce9
8 changed files with 30 additions and 15 deletions

View File

@@ -1,8 +1,8 @@
---
Checks: 'bugprone-*,-bugprone-suspicious-enum-usage,clang-diagnostic-*,clang-analyzer-*,misc-throw-by-value-catch-by-reference,modernize-use-nullptr,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-override,performance-*'
WarningsAsErrors: ''
# -bugprone-chained-comparion is needed for catch2 < v3.5.3
Checks: 'bugprone-*,-bugprone-assignment-in-if-condition,-bugprone-chained-comparison,-bugprone-easily-swappable-parameters,-bugprone-implicit-widening-of-multiplication-result,-bugprone-multi-level-implicit-pointer-conversion,-bugprone-narrowing-conversions,-bugprone-suspicious-enum-usage,-bugprone-switch-missing-default-case,clang-diagnostic-*,clang-analyzer-*,misc-throw-by-value-catch-by-reference,modernize-use-nullptr,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-override,performance-*,-performance-avoid-endl,-performance-enum-size,-performance-no-int-to-ptr'
WarningsAsErrors: '*'
HeaderFilterRegex: '/CorsixTH/Src/|/AnimView/|/common/'
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
- key: cert-dcl16-c.NewSuffixes

View File

@@ -55,7 +55,11 @@ jobs:
- name: Install static analysis requirements
if: matrix.static_analysis
run: |
sudo apt-get install doxygen yamllint clang-format-11 clang-tidy-11
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 20
sudo apt-get install doxygen yamllint clang-format-20 clang-tidy-20
sudo pip3 install -I codespell==2.2 cmakelint==1.4
@@ -130,12 +134,11 @@ jobs:
if: matrix.static_analysis
run: |
# Check cpp format
clang-format-11 -i CorsixTH/Src/*.cpp CorsixTH/Src/*.h AnimView/*.cpp \
clang-format-20 -i CorsixTH/Src/*.cpp CorsixTH/Src/*.h AnimView/*.cpp \
AnimView/*.h libs/rnc/*.cpp libs/rnc/*.h CorsixTH/SrcUnshared/main.cpp
git diff
# Clang-tidy linter
clang-tidy-11 -p build --warnings-as-errors=\* \
CorsixTH/Src/*.c CorsixTH/Src/*.cpp libs/rnc/*.cpp CorsixTH/SrcUnshared/main.cpp
run-clang-tidy-20 -p build
git diff --quiet # exit if clang-format made any changes
- name: Generate documentation
if: matrix.docs

View File

@@ -834,7 +834,7 @@ static bool matchTilePos(const std::string& text, double& x, double& y) {
y = std::stod(num2.c_str());
return true;
} catch (...) {
// Drop into fail return value.
return false;
}
}
return false;
@@ -856,7 +856,7 @@ static bool matchPixelPos(const std::string& text, int& x, int& y) {
y = std::stoi(num2.c_str());
return true;
} catch (...) {
// Drop into fail return value.
return false;
}
}
return false;

View File

@@ -1161,7 +1161,7 @@ int l_persist_dofile(lua_State* L) {
}
size_t iBufferSize = lua_objlen(L, luaT_upvalueindex(1));
size_t iBufferUsed = 0;
while (!std::feof(fFile)) {
while (!std::ferror(fFile) && !std::feof(fFile)) {
iBufferUsed += std::fread(
reinterpret_cast<char*>(lua_touserdata(L, luaT_upvalueindex(1))) +
iBufferUsed,

View File

@@ -862,8 +862,11 @@ void render_target::draw(SDL_Texture* pTexture, const SDL_Rect* prcSrcRect,
getScaleRect(prcDstRect, draw_scale(), &scaledDstRect);
if (current_target) current_target->offset(scaledDstRect);
if (iSDLFlip != 0) {
SDL_RenderCopyExF(renderer, pTexture, prcSrcRect, &scaledDstRect, 0,
nullptr, (SDL_RendererFlip)iSDLFlip);
// iSDLFlip may be 3 (HORIZONTAL | VERTICAL) but there is no enum value for
// that
[[clang::suppress]] SDL_RenderCopyExF(renderer, pTexture, prcSrcRect,
&scaledDstRect, 0, nullptr,
(SDL_RendererFlip)iSDLFlip);
} else {
SDL_RenderCopyF(renderer, pTexture, prcSrcRect, &scaledDstRect);
}

View File

@@ -648,7 +648,7 @@ class sprite_sheet {
//! Height of the sprite.
int height;
} * sprites;
}* sprites;
//! Original palette.
const ::palette* palette;

View File

@@ -48,7 +48,7 @@ uint8_t range_scale(uint16_t low, uint16_t high, uint16_t val, uint16_t start,
}
inline bool is_wall(uint16_t blk) {
return ((82 <= ((blk)&0xFF)) && (((blk)&0xFF) <= 164));
return ((82 <= ((blk) & 0xFF)) && (((blk) & 0xFF) <= 164));
}
inline bool is_wall_drawn(const level_map& map, const map_tile& node,

View File

@@ -36,6 +36,7 @@ SOFTWARE.
#include "rnc.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -187,8 +188,14 @@ static void bitread_init(bit_stream* bs, const std::uint8_t* p,
@param bs Bit stream to correct
*/
static void bitread_fix(bit_stream* bs) {
// Remove the top 16 bits
// Remove the top 16 bits if present
bs->bitcount -= 16;
if (bs->bitcount <= 0) {
bs->bitcount = 0;
}
// bs->bitcount is never greater than 32 and we just subtracted 16
assert(bs->bitcount <= 16);
bs->bitbuf &= (1 << bs->bitcount) - 1;
// Replace with what is in the new current location
@@ -219,6 +226,8 @@ static std::uint32_t bit_peek(bit_stream* bs, const std::uint32_t mask) {
between 0 and 16
*/
static void bit_advance(bit_stream* bs, int n) {
assert(n >= 0 && n <= 16);
bs->bitbuf >>= n;
bs->bitcount -= n;