Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/shell: fix getopt() support #20209

Merged
merged 4 commits into from
Dec 22, 2023
Merged

sys/shell: fix getopt() support #20209

merged 4 commits into from
Dec 22, 2023

Conversation

Enoch247
Copy link
Contributor

Contribution description

This patch adds the missing NULL terminator to the argv passed to shell command handlers. Without it, Newlib's getop() was intermittently causing hardfaults. Closer inspection of NewLib's code revealed that it relies in this NULL termination. ANSI-C also requires it of the argv passed to main().

Also included are some minor improvements to the documentation.

Testing procedure

For me getopt() no longer causes hardfaults. Also code in shell.c now does what the doc in shell.h advertises that it does.

Issues/PRs references

Fixed broken Markdown code spans. Also added a code span around mention
of getopt.
This patch adds details to the rationale behind the design of the
argv/argc handling for shell command handlers. It also fixes a
misspelling.
This patch adds the missing NULL terminator to the argv passed to shell
command handlers. Without it, Newlib's getop() was intermittently
causing hardfaults. Closer inspection of NewLib's code revealed that it
relies in this NULL termination. ANSI-C also requires it of the argv
passed to main().
@github-actions github-actions bot added the Area: sys Area: System label Dec 21, 2023
This patch updates shell.c's doc that undersells the shells complexity.
The comment seems to have been written prior to the shell's ability to
parse command args and handle quoting sequences.
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 21, 2023
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Thank you!
I wasn't even aware we had getopt available, this sure makes makes arg parsing easier.

The required changes are only minor too.

@benpicco benpicco changed the title Fix shell sys/shell: fix getopt() support Dec 21, 2023
@riot-ci
Copy link

riot-ci commented Dec 21, 2023

Murdock results

✔️ PASSED

edb419a sys/shell: update doc

Success Failures Total Runtime
8098 0 8098 10m:56s

Artifacts

@Enoch247
Copy link
Contributor Author

Thank you!

Always happy to contribute.

I wasn't even aware we had getopt available, this sure makes makes arg parsing easier.

Yeah, I've been thrilled with using getopt from the shell once I realized it was provided by the toolchain. It really adds polish to the commands I've created.

The required changes are only minor too.

:) Yep one of those problems that takes hours to figure out and 5 minutes to fix. To be honest, I thought that Newlib was to blame at first. Its getopt.c wasn't the cleanest in my opinion. Kind of amusing that I sometimes assume these well-known projects must be perfect. Then you go look, and realize it's authors are mere mortals too!

@benpicco benpicco added this pull request to the merge queue Dec 21, 2023
Merged via the queue into RIOT-OS:master with commit 3d72a9b Dec 22, 2023
27 checks passed
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.01 milestone Feb 7, 2024
@Enoch247 Enoch247 deleted the fix-shell branch October 21, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants