Skip to content

[WIP] Fix path resolution method in check_directives.sh - #1393

Closed
zandbelt with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-path-resolution-in-check-directives
Closed

[WIP] Fix path resolution method in check_directives.sh#1393
zandbelt with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-path-resolution-in-check-directives

Conversation

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
  • Fix dirname "$0" fallback to use robust path resolution (handle sourced/symlinked scripts)
  • Replace fragile grep -aoE regex with awk-based struct member extraction
  • Replace tr -d ' ' with awk '{print $1}' for portable wc -l whitespace stripping
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The fallback assignment uses `dirname \"$0\"` which may be unreliable if the script is sourced or called through a symlink. Consider using a more robust path resolution method or explicitly documenting that the script must be executed directly.","fixFiles":[{"filePath":"test/check_directives.sh","diff":"diff --git a/test/check_directives.sh b/test/check_directives.sh\n--- a/test/check_directives.sh\n+++ b/test/check_directives.sh\n@@ -35,10 +35,15 @@\n # correct under VPATH/distcheck where the test dir and src dir are siblings in\n # the unpacked source tree), then fall back to build-relative paths.\n dir=\"${srcdir:-}\"\n-[ -n \"$dir\" ] || dir=$(dirname \"$0\")\n+if [ -z \"$dir\" ]; then\n+\tcase \"$0\" in\n+\t\t*/*) dir=$(dirname -- \"$0\") ;;\n+\t\t*) dir=$(pwd) ;;\n+\tesac\n+fi\n \n src=\"\"\n-for cand in \"$dir/../src/cfg/dir.c\" \"../src/cfg/dir.c\" \"$(dirname \"$0\")/../src/cfg/dir.c\"; do\n+for cand in \"$dir/../src/cfg/dir.c\" \"../src/cfg/dir.c\"; do\n \tif [ -f \"$cand\" ]; then\n \t\tsrc=\"$cand\"\n \t\tbreak\n"}]},{"message":"The regex pattern `[A-Za-z_][A-Za-z0-9_]*;` may match identifiers that are not actual struct members (e.g., identifiers in nested comments or strings that survived the comment stripping). Consider adding additional validation or context checks to ensure only valid struct member names are extracted.","fixFiles":[{"filePath":"test/check_directives.sh","diff":"diff --git a/test/check_directives.sh b/test/check_directives.sh\n--- a/test/check_directives.sh\n+++ b/test/check_directives.sh\n@@ -85,7 +85,17 @@\n \t\tif (line ~ /^[ \\t]*#/) next\t\t# skip preprocessor directives\n \t\tprint line\n \t}' \"$src\" |\n-\tgrep -aoE '[A-Za-z_][A-Za-z0-9_]*;' | tr -d ';' | sort -u >\"$tmp_members\"\n+\tawk '\n+\t\t{\n+\t\t\tline = $0\n+\t\t\tgsub(/^[ \\t]+|[ \\t]+$/, \"\", line)\n+\t\t\tif (line == \"\") next\n+\t\t\tif (line !~ /;[ \\t]*$/) next\n+\t\t\tsub(/[ \\t]*;[ \\t]*$/, \"\", line)\n+\t\t\tsub(/\\[[^][]*\\][ \\t]*$/, \"\", line)\n+\t\t\tif (match(line, /[A-Za-z_][A-Za-z0-9_]*[ \\t]*$/))\n+\t\t\t\tprint substr(line, RSTART, RLENGTH)\n+\t\t}' | tr -d ' \\t' | sort -u >\"$tmp_members\"\n \n # members assigned (c->member) inside each function, up to its 'return c;'.\n # Match the function-opening line with a literal index() lookup, not a dynamic\n"}]},{"message":"The use of `tr -d ' '` to strip whitespace from `wc -l` output is fragile and may not work consistently across different implementations of `wc`. Consider using `awk '{print $1}'` or storing the result directly in a more portable way.","fixFiles":[{"filePath":"test/check_directives.sh","diff":"diff --git a/test/check_directives.sh b/test/check_directives.sh\n--- a/test/check_directives.sh\n+++ b/test/check_directives.sh\n@@ -100,7 +100,7 @@\n extract_assigns 'oidc_cfg_dir_config_create(apr_pool_t' >\"$tmp_create\"\n extract_assigns 'oidc_cfg_dir_config_merge(apr_pool_t' >\"$tmp_merge\"\n \n-count=$(wc -l <\"$tmp_members\" | tr -d ' ')\n+count=$(wc -l <\"$tmp_members\" | awk '{print $1}')\n if [ \"$count\" -eq 0 ]; then\n \techo \"ERROR: no oidc_dir_cfg_t members found in $src -- parser out of date?\" >&2\n \texit 1\n"}]}]

@zandbelt zandbelt closed this Jun 18, 2026
Copilot stopped work on behalf of zandbelt due to an error June 18, 2026 15:27
Copilot AI requested a review from zandbelt June 18, 2026 15:27
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.

2 participants