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

psh: fix passing double dash to history, mem and echo #155

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions psh/echo/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ static int psh_echo(int argc, char **argv)
}
}

for (i = optind; i < argend; ++i) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Providing the only option causes early return it can be 1.

if (i != optind) {
for (i = 1; i < argend; ++i) {
if (i != 1) {
fputc(' ', output);
}

Expand Down
7 changes: 4 additions & 3 deletions psh/mem/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static int psh_sharedMaps(void)

static int psh_mem(int argc, char **argv)
{
int c;
int c, ind;

if (argc == 1)
return psh_mem_summary() < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
Expand All @@ -343,8 +343,9 @@ static int psh_mem(int argc, char **argv)
}
}

if (optind < argc) {
fprintf(stderr, "mem: unknown argument: %s\n", argv[optind]);
if (optind <= argc) {
ind = (optind == argc) ? optind - 1 : optind;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Providing the only option causes early return optind == argc will be -- case.

fprintf(stderr, "mem: unknown argument: %s\n", argv[ind]);
return EXIT_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion psh/pshapp/pshapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ int psh_history(int argc, char **argv)
}

/* History command doesn't take any arguments */
if (optind < argc) {
if (optind <= argc && !help && !clear) {
psh_historyhelp();
return EXIT_FAILURE;
}
Expand Down