]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Fix integer expression errors in ASAN log checker
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 18 Oct 2025 14:32:31 +0000 (15:32 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 18 Oct 2025 14:32:31 +0000 (15:32 +0100)
Replace grep -c with wc -l to avoid malformed output when grep
returns results with filenames or multiple lines. The grep -c
command was producing output like "0\n0" instead of a single
integer, causing bash comparison failures.

Use wc -l with tr to ensure clean integer values, and add
error suppression to comparison operators for robustness.

test/integration/scripts/check-asan-logs.sh

index ce87860c506bc2164557147cb4427e860af1a7cd..a5afdfd6c65fad3318d3028a00f4aff037d35990 100755 (executable)
@@ -25,8 +25,9 @@ for log_file in $ASAN_LOGS; do
     echo "----------------------------------------"
 
     # Count memory leaks
-    LEAKS=$(grep -c "LeakSanitizer" "$log_file" 2>/dev/null || echo "0")
-    if [ "$LEAKS" -gt 0 ]; then
+    LEAKS=$(grep "LeakSanitizer" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
+    LEAKS=${LEAKS:-0}
+    if [ "$LEAKS" -gt 0 ] 2>/dev/null; then
         echo "  Memory leaks detected: $LEAKS"
         TOTAL_LEAKS=$((TOTAL_LEAKS + LEAKS))
 
@@ -35,8 +36,9 @@ for log_file in $ASAN_LOGS; do
     fi
 
     # Count other errors
-    ERRORS=$(grep -c "ERROR: AddressSanitizer" "$log_file" 2>/dev/null || echo "0")
-    if [ "$ERRORS" -gt 0 ]; then
+    ERRORS=$(grep "ERROR: AddressSanitizer" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
+    ERRORS=${ERRORS:-0}
+    if [ "$ERRORS" -gt 0 ] 2>/dev/null; then
         echo "  AddressSanitizer errors: $ERRORS"
         TOTAL_ERRORS=$((TOTAL_ERRORS + ERRORS))
 
@@ -45,14 +47,16 @@ for log_file in $ASAN_LOGS; do
     fi
 
     # Check for heap-use-after-free
-    UAF=$(grep -c "heap-use-after-free" "$log_file" 2>/dev/null || echo "0")
-    if [ "$UAF" -gt 0 ]; then
+    UAF=$(grep "heap-use-after-free" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
+    UAF=${UAF:-0}
+    if [ "$UAF" -gt 0 ] 2>/dev/null; then
         echo "  Heap-use-after-free: $UAF"
     fi
 
     # Check for heap-buffer-overflow
-    OVERFLOW=$(grep -c "heap-buffer-overflow" "$log_file" 2>/dev/null || echo "0")
-    if [ "$OVERFLOW" -gt 0 ]; then
+    OVERFLOW=$(grep "heap-buffer-overflow" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
+    OVERFLOW=${OVERFLOW:-0}
+    if [ "$OVERFLOW" -gt 0 ] 2>/dev/null; then
         echo "  Heap-buffer-overflow: $OVERFLOW"
     fi