1 ! Self-modifying reproducing Z-code.
3 ! Generates random junk and sees how the interpreter behaves. If it's clever
4 ! it shouldn't die except for @quit and stack overflow.
6 ! inform \$MAX_STATIC_DATA=40000 crashme.inf
8 ! Written by Evin Robertson 1999. Placed in public domain.
10 Array randstuff -> 32767;
11 Array checkfix -> 257;
15 Array filename string "CRASHME.MEM";
17 #iftrue (#version_number <= 3);
18 Constant Granularity = 2;
19 Constant FileMult = 2;
22 #iftrue (#version_number >= 4 && #version_number <= 5);
23 Constant Granularity = 4;
24 Constant FileMult = 4;
27 #iftrue (#version_number >= 6 && #version_number <= 7);
28 Constant Granularity = 4;
29 Constant FileMult = 8;
32 #iftrue (#version_number == 8);
33 Constant Granularity = 8;
34 Constant FileMult = 8;
38 [ Main i a g r c l t game_size checksum;
39 game_size = FileMult * (0-->13); ! game size
41 r = randstuff % Granularity;
50 print "You are running crashme's output. This will repeat the test run which generated this output.^";
52 print "This program generates random Z-code which is run to test the robustness of your Z-machine interpreter. Most likely this will infinite loop. Do not run if you can't kill your interpreter when it is tightly looping.^Will attempt to write CRASHME.MEM which should be a valid Z-machine game which contains the same code that will be run.^";
54 print "Press 'q' to abort.^";
64 a->i = random(256) - 1;
66 a->i = (emptyfunc * Granularity)->i;
70 checksum = checksum + a->i;
71 g = 0-->6; ! globals location
72 for(i=0: i < 480: i++)
73 checksum = checksum + g->i;
75 for(i=0: i < 257: i++) {
76 if(-255 <= checksum && checksum <= 0) {
77 checkfix->i = -checksum;
81 checksum = checksum + 255;
84 #IFV5; @save 0 game_size filename -> t; #ENDIF;
87 ! reduce the chances that it'll attempt to write over the same file
88 for(i=0: i <= 11: i++)