Fix some warnings reported by CODESonar (#2227)
Remove some unreached/duplicated code. Add error checking for `atoi()` calls. About `isdigit()` and similar functions. The warning reported is: ``` Negative Character Value help isdigit() is invoked here with an argument of signed type char, but only has defined behavior for int arguments that are either representable as unsigned char or equal to the value of macro EOF(-1). Casting the argument to unsigned char will avoid the undefined behavior. In a number of libc implementations, isdigit() is implemented using lookup tables (arrays): passing in a negative value can result in a read underrun. ``` Switching to our macros fix that. Add a check to `check_symbols.sh` to avoid using the original functions from libc.
This commit is contained in:
@@ -19,7 +19,7 @@ for line in `nm -P -u "${NDPI_LIB}"`; do
|
||||
fi
|
||||
|
||||
#printf '%s\n' "${line}"
|
||||
FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\|printf\|fprintf\)$' || true)"
|
||||
FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\|printf\|fprintf\|isdigit\|isalpha\|isalnum\|isspace\|isprint\|ispunct\)$' || true)"
|
||||
|
||||
if [ ! -z "${FOUND_SYMBOL}" ]; then
|
||||
SKIP=0
|
||||
@@ -60,6 +60,6 @@ done
|
||||
|
||||
printf 'Unwanted symbols found: %s\n' "${FAIL_COUNT}"
|
||||
if [ ${FAIL_COUNT} -gt 0 ]; then
|
||||
printf '%s\n' 'Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free wrapper instead of malloc/calloc/realloc/free'
|
||||
printf '%s\n' 'Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free/ndpi_isdigit/ndpi_isalpha/ndpi_isalnum/ndpi_isspace/ndpi_isprint/ndpi_ispunct wrapper instead of malloc/calloc/realloc/free/isdigit/isalpha/isalnum/isspace/isprint/ispunct'
|
||||
fi
|
||||
exit ${FAIL_COUNT}
|
||||
|
||||
Reference in New Issue
Block a user