Attention is currently required from: Martin L Roth.
Elyes Haouas has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/82670?usp=email )
Change subject: util/lint: Warn when <stddef.h> is included but not used ......................................................................
util/lint: Warn when <stddef.h> is included but not used
Change-Id: I49bca3406290a9c3667b54eaa4fb1ffa581302ef Signed-off-by: Elyes Haouas ehaouas@noos.fr --- A util/lint/lint-stable-033-stddef-h 1 file changed, 41 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/70/82670/1
diff --git a/util/lint/lint-stable-033-stddef-h b/util/lint/lint-stable-033-stddef-h new file mode 100755 index 0000000..46d1ed2 --- /dev/null +++ b/util/lint/lint-stable-033-stddef-h @@ -0,0 +1,41 @@ +#!/usr/bin/env sh +# SPDX-License-Identifier: GPL-2.0-or-later +# +# DESCR: Verify if <stddef.h> is needed in modified files +# + +# Get the list of modified files +MODIFIED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '.c$|.h$') +if [ -z "$MODIFIED_FILES" ]; then + exit 0 +fi + +# Create temporary files to hold the lists +TMP_INCLUDE=$(mktemp) +TMP_FUNCTIONS=$(mktemp) + +# Find files including <stddef.h> +for file in $MODIFIED_FILES; do + if grep -q '#include <stddef.h>' "$file"; then + echo "$file" >> "$TMP_INCLUDE" + fi +done + +# Find files using stddef.h functions +for file in $MODIFIED_FILES; do + if grep -q 'ptrdiff_t|size_t|SIZE_MAX|ssize_t|wchar_t|wint_t|NULL|DEVTREE_EARLY|zeroptr' "$file"; then + echo "$file" >> "$TMP_FUNCTIONS" + fi +done + +# Compare the two lists +UNNEEDED_INCLUDE=$(comm -23 "$TMP_INCLUDE" "$TMP_FUNCTIONS") + +# Output warnings for unneeded includes +if [ -n "$UNNEEDED_INCLUDE" ]; then + echo "Warning: The following files include <stddef.h> but do not use its functions:" + echo "$UNNEEDED_INCLUDE" +fi + +# Clean up temporary files +rm -f "$TMP_INCLUDE" "$TMP_FUNCTIONS"