Skip to content

Fix bash crash: replace post-increment with assignment to satisfy set -e#43

Open
sgumil wants to merge 2 commits intoProducdevity:masterfrom
sgumil:fix-bash-crash
Open

Fix bash crash: replace post-increment with assignment to satisfy set -e#43
sgumil wants to merge 2 commits intoProducdevity:masterfrom
sgumil:fix-bash-crash

Conversation

@sgumil
Copy link

@sgumil sgumil commented Dec 14, 2025

Hi, I fixed a crash occurring in patch.sh while running on systems with strict POSIX compliance or specific bash versions.

The issue: The script uses set -e. When using the post increment operator ((count++)) on a variable initialized to 0, bash returns an exit code of 1 because the expression evaluates to 0. This triggers set -e and causes the script to exit immediately.

The fix: I replaced the increment ((count++)) with a standard assignment count=$((count+1)) which removes the ambiguity and avoids false positive error exit code.

Tested and working on Arch Linux.

Closes #51.

Summary by CodeRabbit

  • Refactor
    • Minor internal formatting adjustment to patch handling. No functional changes to behavior or public interfaces; this improves consistency in internal scripts and does not affect end-user functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

Walkthrough

A one-line whitespace normalization was made in patch.sh: the patch redirection in apply_patches now uses a space before the input redirection operator argument. No functional, control-flow, or behavioral changes were introduced.

Changes

Cohort / File(s) Summary
Whitespace normalization
patch.sh
Added a space between the input redirection operator and the patch file in apply_patches (changed "<"$patch_file"" to "< "$patch_file""). No logic or behavior changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A tiny space hopped into the line,
Quietly fixing how patches align,
No fuss, no function changed in sight,
Just tidied code and a calmer night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title is specific and accurately describes the fix: replacing post-increment with assignment to address bash crash when set -e is enabled.
Linked Issues check ✅ Passed The PR addresses issue #51 by fixing the exact problem reported: patch.sh exiting prematurely on systems with strict bash/POSIX compliance when set -e is enabled.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to fixing the post-increment issue in patch.sh; it contains only the minimal whitespace normalization necessary to resolve the set -e crash.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
patch.sh (2)

137-146: Fix is correct: avoids set -e exit-status trap from ((count++)).

count=$((count + 1)) will not return exit code 1 when count was 0, so set -e won’t incorrectly abort the script.

Consider also making target a local (currently implicitly global within the script) to avoid accidental cross-function reuse:

-    while IFS= read -r file; do
-        target="$WORK_DIR/decompiled/$file"
+    while IFS= read -r file; do
+        local target="$WORK_DIR/decompiled/$file"
         if [ -e "$target" ]; then
             rm -rf "$target"
             count=$((count + 1))
         fi
     done < "$PATCHES_DIR/files_to_delete.txt"

186-197: Increment change is good; minor scoping polish available.

count=$((count + 1)) is the right fix under set -e.

Small cleanup to prevent leaking values across functions: declare rel_path, target, target_dir as local inside the loop.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c41deb8 and f5a84cd.

📒 Files selected for processing (1)
  • patch.sh (3 hunks)
🔇 Additional comments (1)
patch.sh (1)

154-174: Counter increments now set -e safe; patch result handling unchanged.

Both count=$((count + 1)) and failed=$((failed + 1)) eliminate the non-obvious nonzero status behavior of ((var++)) under set -e, while preserving the same counter semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patch.sh not completing actions after removing telemetry and unnecessary files. (Endeavouros LXDE)

1 participant