targ1b.pp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. {%skiptarget=wince}
  2. { This file is to check if there is some memory corruption
  3. due to startup code with argument loading
  4. go32v2 target had this problem
  5. close to 2.2 release 2007-03-27 pierre }
  6. program create_startup_test_crash;
  7. {$ifdef go32v2}
  8. {$define HasExeSuffix}
  9. {$endif}
  10. {$ifdef win32}
  11. {$define HasExeSuffix}
  12. {$endif}
  13. {$ifdef win64}
  14. {$define HasExeSuffix}
  15. {$endif}
  16. {$ifdef wince}
  17. {$define HasExeSuffix}
  18. {$endif}
  19. {$ifdef os2}
  20. {$define HasExeSuffix}
  21. {$endif}
  22. {$ifdef emx}
  23. {$define HasExeSuffix}
  24. {$endif}
  25. {$ifdef wdosx}
  26. {$define HasExeSuffix}
  27. {$endif}
  28. {$ifdef netware}
  29. {$define HasNlmSuffix}
  30. {$endif}
  31. {$ifdef netwlibc}
  32. {$define HasNlmSuffix}
  33. {$endif}
  34. uses
  35. dos;
  36. const
  37. ExeSuffix =
  38. {$ifdef HasExeSuffix}
  39. '.exe'
  40. {$else}
  41. {$ifdef HasNlmSuffix}
  42. '.nlm'
  43. {$else}
  44. ''
  45. {$endif}
  46. {$endif}
  47. ;
  48. const
  49. MAX = 255;
  50. var
  51. cmd,
  52. arg : string;
  53. i, first_wrong : longint;
  54. const
  55. Everything_ok : boolean = true;
  56. begin
  57. cmd:='targ1a'+ExeSuffix;
  58. arg:='';
  59. first_wrong:=-1;
  60. for i:=0 to MAX do
  61. begin
  62. Writeln(stderr,'Going to call "',cmd,'" with arg = "',arg,'"');
  63. Writeln(stderr,'arg length =',length(arg));
  64. Exec(cmd,arg);
  65. if (DosExitCode<>0) or (DosError<>0) then
  66. begin
  67. Writeln(stderr,'Crash detected');
  68. if first_wrong=-1 then
  69. first_wrong:=i;
  70. Everything_ok := false;
  71. end;
  72. arg:=arg+'a';
  73. end;
  74. if Everything_ok then
  75. begin
  76. Writeln(stderr,'Test successful: no memory corruption occurs');
  77. end
  78. else
  79. begin
  80. Writeln(stderr,'Test fails: Memory corruption occurs');
  81. Writeln(stderr,'First arg length where error appears is ',first_wrong);
  82. if first_wrong<100 then
  83. RunError(1)
  84. else
  85. Writeln(stderr,'Warning: when using Dos.Exec, arg length must be smaller than ',first_wrong);
  86. end;
  87. end.