Menu

#796 command line -c extra arg bug

Version 6
closed-out-of-date
nobody
None
5
2025-07-21
2022-06-19
Michael Pot
No

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

1 Attachments

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-06-20
     
  • Ethan Merritt

    Ethan Merritt - 2022-06-20

    I think you missed something in the current code.
    The actual number of command line arguments is in variable argc.
    call_argc has been set to argc-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.

     
  • Michael Pot

    Michael Pot - 2022-06-20

    call_argc becomes udv ARGC, so for one actual argument, call_argc == 1. But call_args[] is zero based. call_args[0] is for the first actual argument creating udv ARG1. Not ARG0!

    I think theargc - 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.

     
    • Ethan Merritt

      Ethan Merritt - 2022-06-20

      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

      commit d78e63681f51ebdf942d4a26068a8628308e84f4
      Author: Bastian Maerkisch <bmaerkisch@web.de>
      Date:   Mon Feb 14 14:31:35 2022 +0100
      
          Index overrun for call arguments
      
          Bug #2493
      

      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!

       
  • Michael Pot

    Michael Pot - 2022-06-20

    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.

     
  • Ethan Merritt

    Ethan Merritt - 2022-09-13
    • status: open --> closed-out-of-date
     

Log in to post a comment.