tree-sitter/script/check-mallocs
2024-07-28 10:12:55 +03:00

12 lines
388 B
Bash
Executable file

#!/usr/bin/env bash
src_dir=lib/src
allocation_functions=(malloc calloc realloc free)
for function in "${allocation_functions[@]}"; do
usages=$(grep -n -E "\b${function}\(" -r $src_dir --exclude alloc.c --exclude stdlib.c)
if [[ -n $usages ]]; then
printf 'The %s function should not be called directly, but is called here:\n%s\n' "$function" "$usages" >&2
exit 1
fi
done