forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_suspicious_char_digit_zero.sh
executable file
·46 lines (37 loc) · 1.25 KB
/
detect_suspicious_char_digit_zero.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -eu
SCRIPT_DIR=$(dirname "$0")
case $SCRIPT_DIR in
"/"*)
;;
".")
SCRIPT_DIR=$(pwd)
;;
*)
SCRIPT_DIR=$(pwd)/$(dirname "$0")
;;
esac
GDAL_ROOT=$SCRIPT_DIR/..
cd "$GDAL_ROOT"
ret_code=0
echo "Checking for suspicious comparisons to '0'..."
# Detect comparisons where we'd likely want to check against nul terminating byte in the condition of a for/while loop
if grep -r --include="*.c*" "!= '0'" alg gnm port ogr gcore frmts apps | grep -v libjson ; then
ret_code=1
fi
if grep -r --include="*.c*" "!='0'" alg gnm port ogr gcore frmts apps | grep -v libjson ; then
ret_code=1
fi
# Detect comparisons where we'd likely want to check against nul terminating byte with a if (*pszPtr == '\0'), after interrupting a loop due to a != '\0' check
if grep -r --include="*.c*" "== '0'" alg gnm port ogr gcore frmts apps | grep '\*' ; then
ret_code=1
fi
if grep -r --include="*.c*" "=='0'" alg gnm port ogr gcore frmts apps | grep '\*' ; then
ret_code=1
fi
if [[ $ret_code -eq 1 ]]; then
echo "FAIL: suspicious comparison to '0' found. If valid, replace '0' by a symbolic constant like DIGIT_ZERO = '0' and compare to it"
else
echo "OK: no suspicious comparison to '0' found."
fi
exit $ret_code