targ1b.pp 1.9 KB

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