htool icon indicating copy to clipboard operation
htool copied to clipboard

[joss-review] All examples segfault when run without arguments

Open vijaysm opened this issue 2 months ago • 0 comments

As a follow-up, I was able to build the examples (except for one error). However, as a naive user (before looking into the code directly), every example I ran just segfaulted without any helpful message. IMHO, examples should always assume some standard/valid default values for inputs and should handle user errors gracefully.

Anyway, every example contains checks similar to the one below:

Image

This is a bug, because argc < 1 will never be true. argc should always be 1 or more; argv[0] is typically just an empty string or the executable name. So this check is always false, and hence the usage message will never be printed. However, subsequent access of argv[1] will cause a segfault when, for example, the user does not pass any arguments to the program.

The fix is simple: change your argc check, and you can assume by default that outputpath="." (current directory). Please update all examples to handle this better. Once I realized what was needed, I was able to run all examples.

I was also looking for documentation about the C++ examples, and could not find them. If it makes sense to provide details about what the examples accomplish and how to run different variations, it can be a good tutorial/starting point for new users.

vijaysm avatar Nov 28 '25 05:11 vijaysm