Skip to content

fix: replace fragile option parsing loop with positional loop - #963

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/nvidia-driver-replace-fragile-option-parsing-loop
Open

fix: replace fragile option parsing loop with positional loop#963
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/nvidia-driver-replace-fragile-option-parsing-loop

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in rhel9/nvidia-driver: replace fragile option parsing loop with positional loop.

Changes

  • rhel9/nvidia-driver: replace fragile option parsing loop with positional loop.

Details

--- a/rhel9/nvidia-driver
+++ b/rhel9/nvidia-driver
@@ -1,10 +1,10 @@
-for opt in ${options}; do
-    case "$opt" in
-    -a | --accept-license) ACCEPT_LICENSE="yes"; shift 1 ;;
-    -k | --kernel) KERNEL_VERSION=$2; shift 2 ;;
-    -m | --max-threads) MAX_THREADS=$2; shift 2 ;;
-    -s | --sign) PRIVATE_KEY=$2; shift 2 ;;
-    -t | --tag) PACKAGE_TAG=$2; shift 2 ;;
-    --) shift; break ;;
-    esac
-done
+while [ $# -gt 0 ]; do
+    case "$1" in
+    -a | --accept-license) ACCEPT_LICENSE="yes"; shift 1 ;;
+    -k | --kernel) KERNEL_VERSION=$2; shift 2 ;;
+    -m | --max-threads) MAX_THREADS=$2; shift 2 ;;
+    -s | --sign) PRIVATE_KEY=$2; shift 2 ;;
+    -t | --tag) PACKAGE_TAG=$2; shift 2 ;;
+    --) shift; break ;;
+    esac
+done

Tests

  • tests/test_option_parsing.sh
new file mode 100755
--- /dev/null
+++ tests/test_option_parsing.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -eu
+FILE=rhel9/nvidia-driver
+if grep -F 'for opt in ${options}' $FILE; then
+  echo FAIL: fragile for/opt parsing remains; exit 1
+fi
+if ! grep -F 'while [ $# -gt 0 ]' $FILE; then
+  echo FAIL: while-based parsing not found; exit 1
+fi
+echo PASS

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

1 participant