Dear GNUPlot
gnuplot -c extra arg bug (macports latest gnuplot @5.4.3_0)
While debugging arguments, I note the command line -c option tries to load one more argument into call_args[] than exists on the command line, "<=" needs to be "<"
Attached is a small patch file fixing plot.c which should fix this
patch-gnuplot-c-extra-arg-fix.diff
Many thanks
Michael
I think you missed something in the current code.
The actual number of command line arguments is in variable argc.
call_argchas been set toargc-1(3rd source line in your patch)So the control loop
(i=0; i<=call_argc; i++)is equivalent to
(i=0; i<argc; i++)which is admittedly the more familiar idiom in C but I believe the current code is correct as it stands.
call_argcbecomes udv ARGC, so for one actual argument,call_argc == 1. Butcall_args[]is zero based.call_args[0]is for the first actual argument creating udv ARG1. Not ARG0!I think the
argc - 1(3rd source line in patch), is to account for the command line '-c', not the loop.I found the problem with a debug line in the loop
printf("DEBUG: i=%d call_args[i]=%s\n", i, call_args[i]);Oh, and it is all a bit off putting, Unix always has argc = to 1 as a minimum, as argv[0] is always set == to the program name. A program started with one argument has argc == 2, and argv[1] is the program argument.
Also, a little misleading, is GNUPlot ARG0 is handled separately somehow, so there are a maximum of 9 arguments, stored in the zero based
call_args[]which is declared with places for 10 arguments.Never mind. We're both correct (sort of). You did find an error. And when I looked at the current code in the development source I did find that it was operating correctly. But the error you found was corrected in the code back in February, and no longer exists in the "current code" I looked at.
See
That same fix should have been applied to the 5.4 source, but apparently got missed. Fortunately, your report comes in time to include it in the upcoming 5.4.4 release.
Thanks!
Ah, I see. 2493.patch only fixes misc.c, but I didn't notice further down that Bastian fixed the off by one problem in plot.c (what I reported here). Many thanks.