Files
swupd-client/test/code_analysis/warning_functions.bats
T
Otavio Pontes 6def37a640 tests: Add script to validate if we are using one function we want to avoid
There are some functions we decided to avoid using, so add a test to make
sure we won't add them by accident.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2020-04-02 12:17:54 -07:00

26 lines
828 B
Bash
Executable File

#!/usr/bin/env bats
# Author: Otavio Pontes
# Email: otavio.pontes@intel.com
@test "ANL004: Functions to avoid" {
# There are some C functions that are tricky to use and it's prefered to
# avoid using them in swupd. If any function in this list is really needed
# we need to review the usage and add an exception here.
local functions="strcpy wcscpy strcat wcscat sprintf vsprintf strtok ato strlen wcslen alloca vscanf vsscanf vfscanf scanf sscanf fscanf strncat strsep toa memmove asctime getwd strlen gets"
local error=0
for func in $functions; do
run grep "\<$func(" src --include "*.c" --include "*.h" -R
# shellcheck disable=SC2154
# SC2154: var is referenced but not assigned
if [ "$status" -eq "0" ]; then
echo "Found $func on files:"
echo "$output"
error=1
fi
done
[ "$error" -eq "0" ]
}