Add CI workflow and fix issues with the code
Some checks failed
CI / build-and-analyze (push) Failing after 29s

This commit is contained in:
2026-07-02 11:12:56 +03:00
parent 58526b9ee1
commit 6c050628d0
4 changed files with 2228 additions and 2115 deletions

79
.github/workflows/ci.yaml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: CI
on:
push:
branches: [trunk]
pull_request:
branches: [trunk]
jobs:
build-and-analyze:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install tools
run: |
sudo apt-get update -qq
sudo apt-get install -y build-essential clang clang-tools clang-tidy cppcheck
- name: Build with GCC
run: |
make -f Makefile.posix clean
make -f Makefile.posix CC=gcc CFLAGS="-std=c99 -Wall -Wextra -Wpedantic -Werror -O2"
- name: Build with Clang
run: |
make -f Makefile.posix clean
make -f Makefile.posix CC=clang CFLAGS="-std=c99 -Wall -Wextra -Wpedantic -Werror -O2"
- name: Linting checks
run: |
echo "Running all linting checks..."
FAILED=0
# cppcheck
echo "=== Check 1/4: cppcheck ==="
if make -f Makefile.lint cppcheck; then
echo "cppcheck: PASSED"
else
echo "cppcheck: FAILED"
FAILED=1
fi
# clang-tidy
echo "=== Check 2/4: clang-tidy ==="
if make -f Makefile.lint clang-tidy; then
echo "clang-tidy: PASSED"
else
echo "clang-tidy: FAILED"
FAILED=1
fi
# scan-build
echo "=== Check 3/4: scan-build ==="
if make -f Makefile.lint scan-build; then
echo "scan-build: PASSED"
else
echo "scan-build: FAILED"
FAILED=1
fi
# security-check
echo "=== Check 4/4: security-check ==="
if make -f Makefile.lint security-check; then
echo "security-check: PASSED"
else
echo "security-check: FAILED"
FAILED=1
fi
# Final result
if [ $FAILED -ne 0 ]; then
echo "One or more linting checks failed."
exit 1
else
echo "All linting checks passed."
fi

29
Makefile.lint Normal file
View File

@@ -0,0 +1,29 @@
# Makefile.lint - Individual linting targets
.PHONY: all
all: cppcheck clang-tidy scan-build security-check
@echo "All linting scheduled"
.PHONY: cppcheck
cppcheck:
@echo "Running cppcheck..."
@cppcheck --enable=warning,performance,portability --std=c99 --quiet -Iinclude -I. .
.PHONY: clang-tidy
clang-tidy:
@echo "Running clang-tidy..."
@for file in $$(find . -name "*.c" -type f); do \
clang-tidy "$$file" -- -I. -Iinclude -std=c99; \
done
.PHONY: scan-build
scan-build:
@echo "Running scan-build..."
@scan-build --status-bugs make -f Makefile.posix clean all CC=clang
.PHONY: security-check
security-check:
@echo "Scanning for unsafe C functions..."
@grep -rnE '\b(strcpy|strcat|sprintf|gets|scanf|sscanf|realpath|mktemp|tempnam|tmpnam|getwd|getlogin)\b' \
. --include="*.c" --include="*.h" | grep -v "^Binary file" && \
exit 1 || exit 0

4219
UCD.c

File diff suppressed because it is too large Load Diff

View File

@@ -123,7 +123,7 @@ static struct CaseInfo *caseInfoGet(struct CaseInfo** head, long rune) {
}
if (!(node = malloc(sizeof(*node))))
return NULL;
abort();
memset(node, 0, sizeof(*node));
node->rune = rune;
@@ -262,7 +262,7 @@ static long longIndexGet(long *array) {
static void blocksBuild(void) {
struct CaseInfo *current = caseInfo;
int emitted;
int emitted = -1;
long last = -1;
blockInit(&lowerBlocks, 4, 1, 64, 16, 1);
@@ -352,6 +352,7 @@ static void outputCode(void) {
blockDump(&BLOCK, 3, out, NAME "4", TYPE4)
fprintf(out, "/* Auto-generated case mapping tables */\n\n");
fprintf(out, "#include <stddef.h>\n");
fprintf(out, "#include <stdint.h>\n\n");
DUMP("cat", categoryBlocks, "uint8_t", "uint16_t", "uint16_t", "uint8_t");
@@ -397,7 +398,7 @@ static void outputCode(void) {
fprintf(out, " if(t>=0){\n"); \
fprintf(out, " const int32_t *p=case_data[t];\n"); \
fprintf(out, " size_t i=0;\n"); \
fprintf(out, " while(p[i] && i<3){out[i]=p[i];i++;}\n"); \
fprintf(out, " while(i<3 && p[i]){out[i]=p[i];i++;}\n"); \
fprintf(out, " return i;\n }\n"); \
fprintf(out, " *out=CgeRune" #SIMPLE "(r);\n return 1;\n}\n\n"); \
} while(0)
@@ -426,7 +427,8 @@ static void outputCode(void) {
#undef EMIT_FULL
int main() {
if (!(in = fopen("UnicodeData.txt", "r"))) {
in = fopen("UnicodeData.txt", "r");
if (!in) {
fprintf(stderr, "UnicodeData.txt not found. Download it from:\n");
fprintf(stderr, "https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt\n");
return -1;
@@ -438,7 +440,8 @@ int main() {
entryProcess(in, entryUnicodeData, "<*, First>", "<*, Last>", 1, 0, 15);
fclose(in);
if (!(in = fopen("CaseFolding.txt", "r"))) {
in = fopen("CaseFolding.txt", "r");
if (!in) {
fprintf(stderr, "CaseFolding.txt not found. Download it from:\n");
fprintf(stderr, "https://www.unicode.org/Public/UCD/latest/ucd/CaseFolding.txt\n");
return -1;
@@ -448,7 +451,8 @@ int main() {
fclose(in);
fprintf(stderr, "Processing SpecialCasing.txt\n");
if (!(in = fopen("SpecialCasing.txt", "r"))) {
in = fopen("SpecialCasing.txt", "r");
if (!in) {
fprintf(stderr, "SpecialCasing.txt not found. Download it from:\n");
fprintf(stderr, "https://www.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt\n");
return -1;