Skip to content

Commit

Permalink
Add and apply new clang-tidy config
Browse files Browse the repository at this point in the history
Also adds a CI step for clang-tidy
  • Loading branch information
Zer0-One committed Mar 13, 2024
1 parent bc63634 commit 976f746
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
#-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling: Poorly supported Microsoft shit, not implemented by GCC afaict
#-bugprone-easily-swappable-parameters: you're not my real dad, you can't tell me how to order my parameters
Checks: >
bugprone-*,
concurrency-*,
performance-*,
-bugprone-easily-swappable-parameters,
-bugprone-assignment-in-if-condition,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
17 changes: 16 additions & 1 deletion .github/workflows/build_ship.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,26 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y clang-format

- name: Run Formatting
run: clang-format -i include/* src/*.c src/*.h
run: clang-format -i include/* src/*.h src/*.c

- name: Check Formatting
run: git diff --exit-code

clang-tidy:
runs-on: ubuntu-22.04
steps:
- name : Checkout Source
uses: actions/checkout@v4

- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y clang-tidy libjansson-dev zlib1g-dev libzstd-dev

- name: Configure CMake
run: cmake -DCMAKE_BUILD_TYPE=Debug -DLIBTMJ_TEST=ON -DLIBTMJ_ZSTD=ON -DLIBTMJ_ZLIB=ON .

- name: Tidy
run: clang-tidy include/* src/*.h src/*.c

build-linux:
name: build-${{ matrix.os }}-${{ matrix.cc }}
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.swp
bin/
example/
compile_commands.json
todo.txt

# Doxygen
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY lib)

# Export compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set options
option(LIBTMJ_TEST "Enable unit tests" OFF)
option(LIBTMJ_DOCS "Enable compiling documentation" OFF)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ int main(){
}
```

## Notes

JSON only defines a single number type, meant to accomodate both floating point
values and integers of arbitrary length. This library truncates all input
integers to the size of `int` on your platform, and all input floating point
numbers to the size of `double` on your platform. My estimation is that this is
acceptable for a Tiled map. If you find a case in which this breaks your map,
please let me know.

## License

BSD 2-Clause License
Expand Down
4 changes: 2 additions & 2 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ uint8_t* tmj_zlib_decompress(const uint8_t* data, size_t data_size, size_t* deco
stream.avail_in = data_size;
stream.avail_out = INFLATE_BLOCK_SIZE;

stream.next_in = data;
stream.next_in = data; // NOLINT(clang-diagnostic-incompatible-pointer-types-discards-qualifiers)
stream.next_out = out;

// 15 + 32 for zlib and gzip decoding with automatic header detection, according to the manual
Expand Down Expand Up @@ -213,7 +213,7 @@ uint8_t* tmj_zlib_decompress(const uint8_t* data, size_t data_size, size_t* deco

// clang-format off
const char b64_encode_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char b64_decode_table[] = { 255, 255, 255, 255, 255, 255, 255, 255, 255,
const unsigned char b64_decode_table[] = { 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255,
Expand Down
2 changes: 1 addition & 1 deletion src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void logmsg(tmj_log_priority priority, char* msg, ...) {

va_start(args, msg);

vsnprintf(logmsg_buf, LOGMSG_BUFSIZE, msg, args);
vsnprintf(logmsg_buf, LOGMSG_BUFSIZE, msg, args); // NOLINT(clang-analyzer-valist.Uninitialized)

va_end(args);

Expand Down
6 changes: 4 additions & 2 deletions src/tileset.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ int unpack_tileset(json_t* tileset, Tileset* ret) {
if (ret->tiles == NULL) {
logmsg(TMJ_LOG_ERR, "Unable to unpack tileset[%s]->tiles, the system is out of memory", ret->name);

goto fail_tiles;
goto fail_terrains;
}

size_t idx = 0;
Expand Down Expand Up @@ -499,7 +499,7 @@ int unpack_tileset(json_t* tileset, Tileset* ret) {
goto fail_tiles;
}

ret->tiles[idx].terrain[idx2] = json_integer_value(terrain_idx);
ret->tiles[idx].terrain[idx2] = (int)json_integer_value(terrain_idx);
}
}
}
Expand All @@ -510,10 +510,12 @@ int unpack_tileset(json_t* tileset, Tileset* ret) {
fail_tiles:
for (size_t i = 0; i < ret->tile_count; i++) {
free(ret->tiles[i].animation);

if (ret->tiles[i].objectgroup != NULL) {
free(ret->tiles[i].objectgroup->properties);
free_objects(ret->tiles[i].objectgroup->objects, ret->tiles[i].objectgroup->object_count);
}

free(ret->tiles[i].objectgroup);
free(ret->tiles[i].properties);
}
Expand Down

0 comments on commit 976f746

Please sign in to comment.