clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name save.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/games/adventure/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/games/adventure/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/games/adventure/save.c
| 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; |
| 1 | 'sum' declared without an initial value | |
|
| 126 | int i; |
| 127 | |
| 128 | crc_start(); |
| 129 | for (p = save_array; p->address != NULL; p++) |
| 2 | | Assuming field 'address' is equal to NULL | |
|
| 3 | | Loop condition is false. Execution continues on line 131 | |
|
| 130 | sum = crc(p->address, p->width); |
| 131 | srandom_deterministic((int) sum); |
| 4 | | 1st function call argument is an uninitialized value |
|
| 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; |
| 157 | int i; |
| 158 | |
| 159 | if ((in = fopen(infile, "rb")) == NULL) { |
| 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++) { |
| 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++) |
| 177 | cksum = crc(p->address, p->width); |
| 178 | if (sum != cksum) |
| 179 | return 2; |
| 180 | |
| 181 | |
| 182 | return 0; |
| 183 | } |