ci: add static analysis, sanitizers, and formatting enforcement
CI / lint (push) Failing after 16s
CI / build-and-test (push) Has been skipped
CI / sanitizers (address) (push) Has been skipped
CI / sanitizers (thread) (push) Has been skipped
CI / lint (pull_request) Failing after 30s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (thread) (pull_request) Has been skipped

Add Tier 1 review automation to catch issues before human review:

- Add cppcheck and clang-format to CI lint job
- Add sanitizer matrix (ASan + TSan) CI job
- Enable -Wextra -Wpedantic -Werror in CI build
- Add SANITIZER and STRICT_WARNINGS CMake options
- Add .clang-format for consistent code style
- Update Dockerfile with cppcheck and clang-format
- Fix sign-compare and unused-parameter warnings for -Werror
This commit is contained in:
2026-07-19 15:37:18 +02:00
parent d73d5c9d85
commit 02266710fb
7 changed files with 72 additions and 7 deletions
+10
View File
@@ -0,0 +1,10 @@
BasedOnStyle: LLVM
IndentWidth: 2
ColumnLimit: 100
PointerAlignment: Left
AllowShortFunctionsOnASingleLine: None
SortIncludes: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: true
BinPackParameters: true
+39 -2
View File
@@ -3,15 +3,32 @@ name: CI
on: [push, pull_request]
jobs:
build-and-test:
lint:
runs-on: ubuntu-latest
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install lint tools
run: apt-get update && apt-get install -y cppcheck clang-format
- name: clang-format check
run: clang-format --dry-run --Werror src/ tests/
- name: cppcheck
run: cppcheck --enable=warning,style,performance,portability --suppress=missingIncludeSystem --error-exitcode=1 --inline-suppr src/ tests/
build-and-test:
runs-on: ubuntu-latest
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: cmake -B build -S .
run: cmake -B build -S . -DSTRICT_WARNINGS=ON
- name: Build
run: cmake --build build -j$(nproc)
@@ -21,3 +38,23 @@ jobs:
- name: Integration Tests
run: python3 -m pytest tests/ -v --tb=short
sanitizers:
runs-on: ubuntu-latest
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
needs: lint
strategy:
matrix:
sanitizer: [address, thread]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: cmake -B build-${{ matrix.sanitizer }} -S . -DSANITIZER=${{ matrix.sanitizer }}
- name: Build
run: cmake --build build-${{ matrix.sanitizer }} -j$(nproc)
- name: Unit Tests
run: ./build-${{ matrix.sanitizer }}/tests
+19 -2
View File
@@ -7,9 +7,26 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_compile_options(-Wall -g -O3)
# add_compile_options(-Wall -g -O1 -fsanitize=address)
# add_link_options(-fsanitize=address)
# --- Sanitizer option ---
set(SANITIZER "none" CACHE STRING "Sanitizer to enable (address, thread, none)")
set_property(CACHE SANITIZER PROPERTY STRINGS address thread none)
if(SANITIZER STREQUAL "address")
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g)
add_link_options(-fsanitize=address)
elseif(SANITIZER STREQUAL "thread")
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer -g)
add_link_options(-fsanitize=thread)
elseif(NOT SANITIZER STREQUAL "none")
message(FATAL_ERROR "Unknown sanitizer: ${SANITIZER}. Supported values: address, thread, none")
endif()
# --- Strict warnings option ---
option(STRICT_WARNINGS "Enable strict warnings (Wextra, Wpedantic, Werror)" OFF)
if(STRICT_WARNINGS)
add_compile_options(-Wextra -Wpedantic -Werror)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
+1 -1
View File
@@ -1,6 +1,6 @@
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc g++ make libc6-dev cmake libzstd-dev libssl-dev git ca-certificates curl \
gcc g++ make libc6-dev cmake libzstd-dev libssl-dev git ca-certificates curl cppcheck clang-format \
python3 python3-pip python3-venv openssl openssh-client && \
pip3 install --break-system-packages pytest && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
+1
View File
@@ -7,6 +7,7 @@
#define INITIAL_DECOMPRESS_BUF_SIZE (1024 * 1024)
Data *data_compress(Data *data_to_compress, int compression_level) {
(void)compression_level;
log_message(LOG_LEVEL_DEBUG, "Starting to compress data");
size_t dst_size = ZSTD_compressBound(data_to_compress->size);
Data *compressed_data = data_create_empty(dst_size);
+1 -1
View File
@@ -235,7 +235,7 @@ bool file_send_sendfile(File *file, int file_descriptor, bool use_metadata, bool
}
off_t offset = 0;
while (offset < file_size) {
while ((unsigned long long)offset < file_size) {
ssize_t sent = sendfile(file_descriptor, fd, &offset, file_size - offset);
if (sent == -1) {
perror("sendfile failed");
+1 -1
View File
@@ -68,7 +68,7 @@ bool send_n_data(int file_descriptor, void *data, size_t data_size) {
log_message(LOG_LEVEL_DEBUG, " Sending n Data: %zu", data_size);
int fd = io_fd(io_write_fd, file_descriptor);
ssize_t total_bytes_send = 0;
while (total_bytes_send < data_size) {
while ((size_t)total_bytes_send < data_size) {
size_t chunk = data_size - total_bytes_send;
if (io_bwlimit > 0 && chunk > 65536)
chunk = 65536;