1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | #include <stdio.h> |
39 | #include <stdlib.h> |
40 | |
41 | #include "extern.h" |
42 | #include "hdr.h" |
43 | |
44 | struct savestruct |
45 | { |
46 | void *address; |
47 | int width; |
48 | }; |
49 | |
50 | struct savestruct save_array[] = |
51 | { |
52 | {&abbnum, sizeof(abbnum)}, |
53 | {&attack, sizeof(attack)}, |
54 | {&blklin, sizeof(blklin)}, |
55 | {&bonus, sizeof(bonus)}, |
56 | {&chloc, sizeof(chloc)}, |
57 | {&chloc2, sizeof(chloc2)}, |
58 | {&clock1, sizeof(clock1)}, |
59 | {&clock2, sizeof(clock2)}, |
60 | {&closed, sizeof(closed)}, |
61 | {&closng, sizeof(closng)}, |
62 | {&daltlc, sizeof(daltlc)}, |
63 | {&demo, sizeof(demo)}, |
64 | {&detail, sizeof(detail)}, |
65 | {&dflag, sizeof(dflag)}, |
66 | {&dkill, sizeof(dkill)}, |
67 | {&dtotal, sizeof(dtotal)}, |
68 | {&foobar, sizeof(foobar)}, |
69 | {&gaveup, sizeof(gaveup)}, |
70 | {&holdng, sizeof(holdng)}, |
71 | {&iwest, sizeof(iwest)}, |
72 | {&k, sizeof(k)}, |
73 | {&k2, sizeof(k2)}, |
74 | {&knfloc, sizeof(knfloc)}, |
75 | {&kq, sizeof(kq)}, |
76 | {&latncy, sizeof(latncy)}, |
77 | {&limit, sizeof(limit)}, |
78 | {&lmwarn, sizeof(lmwarn)}, |
79 | {&loc, sizeof(loc)}, |
80 | {&maxdie, sizeof(maxdie)}, |
81 | {&mxscor, sizeof(mxscor)}, |
82 | {&newloc, sizeof(newloc)}, |
83 | {&numdie, sizeof(numdie)}, |
84 | {&obj, sizeof(obj)}, |
85 | {&oldlc2, sizeof(oldlc2)}, |
86 | {&oldloc, sizeof(oldloc)}, |
87 | {&panic, sizeof(panic)}, |
88 | {&savet, sizeof(savet)}, |
89 | {&scorng, sizeof(scorng)}, |
90 | {&spk, sizeof(spk)}, |
91 | {&stick, sizeof(stick)}, |
92 | {&tally, sizeof(tally)}, |
93 | {&tally2, sizeof(tally2)}, |
94 | {&tkk, sizeof(tkk)}, |
95 | {&turns, sizeof(turns)}, |
96 | {&verb, sizeof(verb)}, |
97 | {&wd1, sizeof(wd1)}, |
98 | {&wd2, sizeof(wd2)}, |
99 | {&wzdark, sizeof(wzdark)}, |
100 | {&yea, sizeof(yea)}, |
101 | {atloc, sizeof(atloc)}, |
102 | {dloc, sizeof(dloc)}, |
103 | {dseen, sizeof(dseen)}, |
104 | {fixed, sizeof(fixed)}, |
105 | {hinted, sizeof(hinted)}, |
106 | {linkx, sizeof(linkx)}, |
107 | {odloc, sizeof(odloc)}, |
108 | {place, sizeof(place)}, |
109 | {prop, sizeof(prop)}, |
110 | {tk, sizeof(tk)}, |
111 | |
112 | {NULL, 0} |
113 | }; |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | int |
120 | save(const char *outfile) |
121 | { |
122 | FILE *out; |
123 | struct savestruct *p; |
124 | char *s; |
125 | long sum; |
126 | int i; |
127 | |
128 | crc_start(); |
129 | for (p = save_array; p->address != NULL; p++) |
130 | sum = crc(p->address, p->width); |
131 | srandom_deterministic((int) sum); |
132 | |
133 | if ((out = fopen(outfile, "wb")) == NULL) { |
134 | fprintf(stderr, |
135 | "Hmm. The name \"%s\" appears to be magically blocked.\n", |
136 | outfile); |
137 | return 1; |
138 | } |
139 | |
140 | fwrite(&sum, sizeof(sum), 1, out); |
141 | for (p = save_array; p->address != NULL; p++) { |
142 | for (s = p->address, i = 0; i < p->width; i++, s++) |
143 | *s = (*s ^ random()) & 0xFF; |
144 | fwrite(p->address, p->width, 1, out); |
145 | } |
146 | fclose(out); |
147 | return 0; |
148 | } |
149 | |
150 | int |
151 | restore(const char *infile) |
152 | { |
153 | FILE *in; |
154 | struct savestruct *p; |
155 | char *s; |
156 | long sum, cksum; |
| 1 | 'cksum' declared without an initial value | |
|
157 | int i; |
158 | |
159 | if ((in = fopen(infile, "rb")) == NULL) { |
| 2 | | Assuming the condition is false | |
|
| |
160 | fprintf(stderr, |
161 | "Hmm. The file \"%s\" appears to be magically blocked.\n", |
162 | infile); |
163 | return 1; |
164 | } |
165 | |
166 | fread(&sum, sizeof(sum), 1, in); |
167 | srandom_deterministic((unsigned int) sum); |
168 | for (p = save_array; p->address != NULL; p++) { |
| 4 | | Assuming field 'address' is equal to NULL | |
|
| 5 | | Loop condition is false. Execution continues on line 173 | |
|
169 | fread(p->address, p->width, 1, in); |
170 | for (s = p->address, i = 0; i < p->width; i++, s++) |
171 | *s = (*s ^ random()) & 0xFF; |
172 | } |
173 | fclose(in); |
174 | |
175 | crc_start(); |
176 | for (p = save_array; p->address != NULL; p++) |
| 6 | | Assuming field 'address' is equal to NULL | |
|
| 7 | | Loop condition is false. Execution continues on line 178 | |
|
177 | cksum = crc(p->address, p->width); |
178 | if (sum != cksum) |
| 8 | | The right operand of '!=' is a garbage value |
|
179 | return 2; |
180 | |
181 | |
182 | return 0; |
183 | } |