Segmentation fault when invoking with --help? (minor)
Low priority issue but a strange one, so I thought documenting it here would open discussion.
On my fork, or freshly clones original repo, the same behaviour is seen:
>./todo.sh --help
Shows help and then stops with "Fatal Error: Cannot read configuration file ", which is as expected.
However, when supplying a config file:
>./todo.sh -d todo.cfg --help Segmentation fault: 11
What could cause this?
@PedroLopes Is this still happening?
If so, could you provide your OS and shell versions.
I'm experiencing the same issue. I'm storing everything in dropbox, and have aliased t to ~/Dropbox/todo/todo.sh -d ~/Dropbox/todo/todo.cfg.
t ls works as expected.
t help works as expected.
t shorthelp works as expected.
t -h works as expected.
t --help causes Segmentation fault: 11.
I'm on OSX Sierra with GNU bash, version 3.2.57, and this todo.sh was downloaded from this repository on Aug 21, 2017.
@gms8994 exactly my setup & extacly my problem. I am on an old OSX (mountain lion) but would not expect that to be the issue.
@karbassi : sure, thanks for asking, here you go:
shell
bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
Copyright (C) 2007 Free Software Foundation, Inc.
p.s.: this is all inside an Iterm (version: 2.-9)
OS
uname -a
Darwin pedro 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64
system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: OS X 10.8.2 (12C60)
I've taken a look, but I can't seem to find where the --help flag is caught and ran.
I know what is causing the error though. If you look at the usage line, it reads:
todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Notice that [-d todo_config] is after the flags.
Moreover, todo.sh -h and todo.sh --help should produce the same output, which is true, if and only if -d TODO_CONFIG is not set before it.
The more I look into it, it looks like a loop going wrong.
@karbassi you are correct. Running todo.sh --help works as expected. Running todo.sh --help -d todo.cfg works as expected as well. Moving the -d todo.cfg before the --help triggers the failure.
I put some debugging output in the loop at https://github.com/todotxt/todo.txt-cli/blob/master/todo.sh#L484 (just a simple echo $Option) and ran todo.sh --help -d todo.cfg. The output is ?, h, ?, ?, p, implying that it's looking at all of the individual characters in the option. Running todo.sh -d todo.cfg --help. The output is d, ?, h, Segmentation fault: 11. The loop successfully runs through the h flag (as evidenced by placing a echo "HI" after all code in that case), and then fails before outputting the e.
Maybe the simplest solution in this case is to just check all of the values passed to todo.sh for --help, and short-circuit to the help text?
A rewrite of that loop will be a good idea. Here is a good example.
The same thing is happening to me, running todo.sh -d .todo/config --help.
On a side note: I'm not sure which version of todo.sh I'm running; calling todo.sh -V prints TODO.TXT Command Line Interface v@DEV_VERSION@, but that seems to be a separate issue altogether.
@inkarkat I think this is fixed by now, can the issue be closed?
$ ./todo.sh -d todo.cfg --help
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Try 'todo.sh -h' for more information.
Yep, I also don't get a segfault. Closing.