logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: b6914ef5771bceabc513e4198ea5c2891042b5c9
parent bb279ddf89d7e9d6a93437d9044393661a1a9789
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 14 Mar 2022 19:17:20 +0100

Add support for linting via flawfinder

Diffstat:

MMakefile1+
Mbin/echo.c1+
Mbin/sizeof.c11++++++-----
Mconfigure11+++++++++++
4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,6 +12,7 @@ test: all lint: $(SHELLCHECK) ./configure test_all.sh test_functions.sh SHELLCHECK=${SHELLCHECK} ./test-bin/shellcheck + ${FLAWFINDER} --error-level=4 . cd bin ; $(MAKE) lint cd sbin ; $(MAKE) lint diff --git a/bin/echo.c b/bin/echo.c @@ -35,6 +35,7 @@ main(int argc, char *argv[]) buffer_p = buffer; for(int i = 1; i < argc; i++) { + /* flawfinder: ignore, consider that arguments are safely separated by NULL */ buffer_p = strcpy(buffer_p, argv[i]); buffer_p += strlen(buffer_p); diff --git a/bin/sizeof.c b/bin/sizeof.c @@ -8,13 +8,12 @@ #include <stdio.h> #include <stdlib.h> -static const char *format = "sizeof(%s) == %d bytes; %d bits\n"; -static const char *format_m = "sizeof(%s) == %d bytes; %d bits; (MIN:MAX) == (%d:%d)\n"; +#define FORMAT_M "sizeof(%s) == %d bytes; %d bits; (MIN:MAX) == (%d:%d)\n" static void print_size(size_t size, char *type) { - printf(format, type, size, size * CHAR_BIT); + printf("sizeof(%s) == %d bytes; %d bits\n", type, size, size * CHAR_BIT); } int @@ -25,9 +24,11 @@ main(void) printf("CHAR_BIT == %d\n", CHAR_BIT); c = sizeof(int); - printf(format_m, "int", c, c * CHAR_BIT, INT_MIN, INT_MAX); + /* flawfinder: ignore. Not given by user but by a macro */ + printf(FORMAT_M, "int", c, c * CHAR_BIT, INT_MIN, INT_MAX); c = sizeof(char); - printf(format_m, "char", c, c * CHAR_BIT, CHAR_MIN, CHAR_MAX); + /* flawfinder: ignore. Not given by user but by a macro */ + printf(FORMAT_M, "char", c, c * CHAR_BIT, CHAR_MIN, CHAR_MAX); print_size(sizeof(uint8_t), "uint8_t"); print_size(sizeof(short), "short"); diff --git a/configure b/configure @@ -18,6 +18,7 @@ Variables: MAKE=BIN MANDOC=BIN SHELLCHECK=BIN + FLAWFINDER=BIN GCOV=BIN CFLAGS=OPTIONS @@ -88,6 +89,7 @@ CFLAGS="${CFLAGS:--g -O2 -pie -fPIE}" LDFLAGS="${LDFLAGS:--Wl,--as-needed}" MANDOC="${MANDOC:-mandoc}" SHELLCHECK="${SHELLCHECK:-shellcheck}" +FLAWFINDER="${FLAWFINDER:-flawfinder}" # Also allow variables through arguments for i; do @@ -158,6 +160,14 @@ else SHELLCHECK="true" fi +if check_cmd FLAWFINDER "$FLAWFINDER" +then + : +else + echo 'Notice: Linting depending on flawfinder disabled' + FLAWFINDER="true" +fi + echo # pkg-config @@ -206,6 +216,7 @@ CC = ${CC} MAKE = ${MAKE} MANDOC = ${MANDOC} SHELLCHECK = ${SHELLCHECK} +FLAWFINDER = ${FLAWFINDER} MSGFMT = ${MSGFMT} DBG = ${DBG} GCOV = ${GCOV}