www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/21/18:58:36

Date: Sun, 21 Aug 94 15:04 PDT
From: jdp AT polstra DOT com (John Polstra)
To: djgpp AT polstra DOT com
Subject: Bug in 1.12 "go32/control.c" (with patch)

I happened to notice (thanks to a compiler warning) that the local
variable "argc" is used before it is set in "go32/control.c" function
"set_command_line".  Depending on what random value the variable
contained at that point, it could cause a spurious fatal error
message:

    Fatal! no memory to copy arguments (max 1000, wanted %d)

Also, the number printed in the message would be wrong, because the value
of "argv" (a pointer) was printed instead of "argc".

A patch is appended.

   John Polstra                                       jdp AT polstra DOT com
   John D. Polstra & Co., Inc.                   Phone (206) 932-6482
   Seattle, Washington USA                         Fax (206) 935-1262
   "Self-knowledge is always bad news."                 -- John Barth


*** go32/control.c-	Sat Jul 30 21:20:38 1994
--- go32/control.c	Sun Aug 21 14:47:25 1994
***************
*** 1090,1096 ****
  
    a = (word32 *)transfer_buffer;
    if (argc > 1000)
    {
!     fprintf(stderr, "Fatal! no memory to copy arguments (max 1000, wanted %d)\n", argv);
      exit(1);
    }
--- 1090,1097 ----
  
    a = (word32 *)transfer_buffer;
+   for (argc=0; argv[argc]; argc++);
    if (argc > 1000)
    {
!     fprintf(stderr, "Fatal! no memory to copy arguments (max 1000, wanted %d)\n", argc);
      exit(1);
    }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019