home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / os2 / programm / 4518 < prev    next >
Encoding:
Text File  |  1992-08-29  |  1.2 KB  |  42 lines

  1. Path: sparky!uunet!olivea!decwrl!borland.com!alexande
  2. From: alexande@genghis.borland.com (Mark Alexander)
  3. Newsgroups: comp.os.os2.programmer
  4. Subject: Findfirst in DOS box can crash OS/2
  5. Message-ID: <1992Aug28.194103.5195@genghis.borland.com>
  6. Date: 28 Aug 92 19:41:03 GMT
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. Lines: 30
  10. Originator: alexande@genghis.borland.com
  11.  
  12.  
  13. Using the 'findfirst' system call in a DOS program can crash OS/2 2.0
  14. 6.307 if the filename argument is very close to the end of the stack
  15. segment.  In my test program, the filename being searched for was
  16. "blorch", and was stored at SS:FFF6.  This can happen if you are using
  17. Borland C++, and the filename is passed on the command line.
  18.  
  19. The workaround is to use strdup() to make a copy of the filename in
  20. a "safer" location.
  21.  
  22. Here is the test program.  I compiled it with BC++ 3.1 using small model.
  23.  
  24. #include <stdio.h>
  25. #include <dir.h>
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.     struct ffblk ffile;
  30.  
  31.     if (argc != 2)
  32.     {
  33.         printf("You must supply one argument.\n");
  34.         return 1;
  35.     }
  36.     if (findfirst(argv[1],&ffile,0x3f) != 0)
  37.         printf("Unable to find %s\n", argv[1]);
  38.     else
  39.         printf("Found %s\n", argv[1]);
  40.     return 0;
  41. }
  42.