Added sanitize.

Pascal J. Bourguignon [2020-10-06 01:13]
Added sanitize.
Filename
sanitize
diff --git a/sanitize b/sanitize
new file mode 100755
index 0000000..1d41859
--- /dev/null
+++ b/sanitize
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# https://termbin.com/683a
+
+sanitize_ld=(
+    -fsanitize=leak
+)
+
+sanitize_cc=(
+    -fsanitize=address
+    -fsanitize=null
+    -fsanitize=bounds
+    -fsanitize=vla-bound
+    # -fsanitize=object-size # not with -O0
+
+    -fsanitize=unreachable
+    -fsanitize=return # C++ only
+
+    # -fsanitize=shift
+    # -fsanitize=shift-exponent
+    # -fsanitize=shift-base
+    # -fsanitize=integer-divide-by-zero
+    # -fsanitize=signed-integer-overflow
+
+    -fsanitize=float-divide-by-zero
+    -fsanitize=float-cast-overflow
+    -fsanitize=nonnull-attribute
+    -fsanitize=returns-nonnull-attribute
+    -fsanitize=bool
+    -fsanitize=enum
+    # -fsanitize=vptr # C++ only and not with -fsanitize-undefined-trap-on-error
+
+
+    -fsanitize-address-use-after-scope
+    -fsanitize-undefined-trap-on-error
+    -fstack-protector-all
+    -fstack-check
+)
+
+
+function trim_spaces(){
+    local string="$1"
+    # ${a## } or ${a%% } doesn't work! (in bash 4.3).
+    string="$(echo "$string" | sed -e 's/^ *//' -e 's/ *$//')"
+    echo -n "${string}"
+}
+
+function trim_colons(){
+    local string="$1"
+    string="$(echo "$string" | sed -e 's/^:*//' -e 's/:*$//')"
+    echo -n "${string}"
+}
+
+
+export CFLAGS=$(trim_spaces "${CFLAGS:-} ${sanitize_cc[*]} -g -g3 -ggdb -O0")
+export LDFLAGS=$(trim_spaces "${LDFLAGS:-} ${sanitize_ld[*]}")
+
+
+gcc ${CFLAGS} ${LDFLAGS} $@
+
+
ViewGit