readexe icon indicating copy to clipboard operation
readexe copied to clipboard

Invoking `readexe` without arguments gives garbage

Open segin opened this issue 3 years ago • 1 comments

More precisely, when invoking readexe without any arguments, the "not enough arguments" message is normally prefixed with the program's name; however, the included err.c functions instead get the message prefixed with nothing, or worse, random garbage, like this DOSbox screenshot of the Watcom 16-bit DOS build shows:

image

Ideally, it should read readexe or READEXE.EXE or something similar.

segin avatar Aug 07 '23 14:08 segin

Defining NEED_ERR for the preprocessor was all that was required. The failure was in the failure to call setprogname() in main() as it was conditionally compiled only if NEED_ERR was set. As a result, err()-family functions would use the pointer returned by getprogname(), stored in the __progname variable. Unfortunately, this is only initialized by a call to setprogname(), and without this call, the value of __progname is undefined.

image

segin avatar Aug 07 '23 16:08 segin