{{ message }}
lib/gis: Replace non-reentrant strtok with thread-safe strtok_r#7595
Draft
NeelGhoshal wants to merge 1 commit into
Draft
lib/gis: Replace non-reentrant strtok with thread-safe strtok_r#7595NeelGhoshal wants to merge 1 commit into
NeelGhoshal wants to merge 1 commit into
Conversation
Replace all uses of the non-reentrant strtok() with strtok_r() in the GIS parser modules to improve thread safety. Affected functions: - G__usage_xml() in parser_interface.c: two tokenization loops (key_desc and gisprompt parsing) - G__wps_print_process_description() in parser_wps.c: three tokenization loops (gisprompt x2, key_desc) - wps_print_literal_input_output() in parser_wps.c: range parsing Each call site introduces a local saveptr variable so the reentrant state is kept per-call rather than in a hidden global buffer.
Contributor
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
Suggested change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Replace all calls to the non-reentrant
strtok()withstrtok_r()inparser_interface.candparser_wps.c. Each call site introduces a localsaveptrvariable so tokenization state is kept per-invocation rather thanin a hidden global buffer.
Affected functions:
G__usage_xml()inparser_interface.c—key_descandgisprompttokenization loopsG__wps_print_process_description()inparser_wps.c— three tokenization loops (gisprompt×2,key_desc)wps_print_literal_input_output()inparser_wps.c— range value parsingMotivation and context
strtok()uses a hidden global buffer, making it unsafe in multithreadedcontexts and fragile if any callee also calls
strtok().strtok_r()isthe POSIX reentrant equivalent and is supported on all platforms GRASS targets.
How has this been tested?
The changed functions are exercised by the existing test suites in:
lib/gis/testsuite/test_parser_json.pylib/gis/tests/lib_gis_parser_json_test.pyNo new behaviour is introduced — only the internal tokenization mechanism changes.
Types of changes
Checklist