clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hack.save.c -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 -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -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/hack/obj -resource-dir /usr/local/llvm16/lib/clang/16 -I . -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/games/hack/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fno-jump-tables -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/scan/2024-01-11-140451-98009-1 -x c /usr/src/games/hack/hack.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 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | #include <signal.h> |
| 65 | #include <stdio.h> |
| 66 | #include <stdlib.h> |
| 67 | #include <unistd.h> |
| 68 | |
| 69 | #include "hack.h" |
| 70 | |
| 71 | extern char genocided[60]; |
| 72 | extern char fut_geno[60]; |
| 73 | extern char SAVEF[], nul[]; |
| 74 | extern char pl_character[PL_CSIZ]; |
| 75 | |
| 76 | static int dosave0(int); |
| 77 | |
| 78 | int |
| 79 | dosave(void) |
| 80 | { |
| 81 | if(dosave0(0)) { |
| 82 | settty("Be seeing you ...\n"); |
| 83 | exit(0); |
| 84 | } |
| 85 | return(0); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | hackhangup(int notused) |
| 90 | { |
| 91 | (void) dosave0(1); |
| 92 | exit(1); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | static int |
| 97 | dosave0(int hu) |
| 98 | { |
| 99 | int fd, ofd; |
| 100 | int tmp; |
| 101 | |
| 102 | (void) signal(SIGHUP, SIG_IGN); |
| 103 | (void) signal(SIGINT, SIG_IGN); |
| 104 | if((fd = open(SAVEF, O_CREAT | O_TRUNC | O_WRONLY, FMASK)) == -1) { |
| 105 | if(!hu) pline("Cannot open save file. (Continue or Quit)"); |
| 106 | (void) unlink(SAVEF); |
| 107 | return(0); |
| 108 | } |
| 109 | if(flags.moonphase == FULL_MOON) |
| 110 | u.uluck--; |
| 111 | savelev(fd,dlevel); |
| 112 | saveobjchn(fd, invent); |
| 113 | saveobjchn(fd, fcobj); |
| 114 | savemonchn(fd, fallen_down); |
| 115 | tmp = getuid(); |
| 116 | bwrite(fd, &tmp, sizeof tmp); |
| 117 | bwrite(fd, &flags, sizeof(struct flag)); |
| 118 | bwrite(fd, &dlevel, sizeof dlevel); |
| 119 | bwrite(fd, &maxdlevel, sizeof maxdlevel); |
| 120 | bwrite(fd, &moves, sizeof moves); |
| 121 | bwrite(fd, &u, sizeof(struct you)); |
| 122 | if(u.ustuck) |
| 123 | bwrite(fd, &(u.ustuck->m_id), sizeof u.ustuck->m_id); |
| 124 | bwrite(fd, pl_character, sizeof pl_character); |
| 125 | bwrite(fd, genocided, sizeof genocided); |
| 126 | bwrite(fd, fut_geno, sizeof fut_geno); |
| 127 | savenames(fd); |
| 128 | for(tmp = 1; tmp <= maxdlevel; tmp++) { |
| 129 | extern int hackpid; |
| 130 | extern boolean level_exists[]; |
| 131 | |
| 132 | if(tmp == dlevel || !level_exists[tmp]) continue; |
| 133 | glo(tmp); |
| 134 | if((ofd = open(lock, O_RDONLY)) == -1) { |
| 135 | if(!hu) pline("Error while saving: cannot read %s.", lock); |
| 136 | (void) close(fd); |
| 137 | (void) unlink(SAVEF); |
| 138 | if(!hu) done("tricked"); |
| 139 | return(0); |
| 140 | } |
| 141 | getlev(ofd, hackpid, tmp); |
| 142 | (void) close(ofd); |
| 143 | bwrite(fd, &tmp, sizeof tmp); |
| 144 | savelev(fd,tmp); |
| 145 | (void) unlink(lock); |
| 146 | } |
| 147 | (void) close(fd); |
| 148 | glo(dlevel); |
| 149 | (void) unlink(lock); |
| 150 | glo(0); |
| 151 | (void) unlink(lock); |
| 152 | return(1); |
| 153 | } |
| 154 | |
| 155 | int |
| 156 | dorecover(int fd) |
| 157 | { |
| 158 | int nfd; |
| 159 | int tmp; |
| 160 | unsigned mid; |
| 1 | 'mid' declared without an initial value | |
|
| 161 | struct obj *otmp; |
| 162 | extern boolean restoring; |
| 163 | |
| 164 | restoring = TRUE; |
| 165 | getlev(fd, 0, 0); |
| 166 | invent = restobjchn(fd); |
| 167 | for(otmp = invent; otmp; otmp = otmp->nobj) |
| 2 | | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is false. Execution continues on line 170 | |
|
| 168 | if(otmp->owornmask) |
| 3 | | Assuming field 'owornmask' is 0 | |
|
| |
| 169 | setworn(otmp, otmp->owornmask); |
| 170 | fcobj = restobjchn(fd); |
| 171 | fallen_down = restmonchn(fd); |
| 172 | mread(fd, (char *) &tmp, sizeof tmp); |
| 173 | if(tmp != getuid()) { |
| 6 | | Assuming the condition is false | |
|
| |
| 174 | (void) close(fd); |
| 175 | (void) unlink(SAVEF); |
| 176 | puts("Saved game was not yours."); |
| 177 | restoring = FALSE; |
| 178 | return(0); |
| 179 | } |
| 180 | mread(fd, (char *) &flags, sizeof(struct flag)); |
| 181 | mread(fd, (char *) &dlevel, sizeof dlevel); |
| 182 | mread(fd, (char *) &maxdlevel, sizeof maxdlevel); |
| 183 | mread(fd, (char *) &moves, sizeof moves); |
| 184 | mread(fd, (char *) &u, sizeof(struct you)); |
| 185 | if(u.ustuck) |
| 8 | | Assuming field 'ustuck' is null | |
|
| |
| 186 | mread(fd, (char *) &mid, sizeof mid); |
| 187 | mread(fd, (char *) pl_character, sizeof pl_character); |
| 188 | mread(fd, (char *) genocided, sizeof genocided); |
| 189 | mread(fd, (char *) fut_geno, sizeof fut_geno); |
| 190 | restnames(fd); |
| 191 | while(1) { |
| 10 | | Loop condition is true. Entering loop body | |
|
| 192 | if(read(fd, (char *) &tmp, sizeof tmp) != sizeof tmp) |
| 11 | | Assuming the condition is true | |
|
| |
| 193 | break; |
| 194 | getlev(fd, 0, tmp); |
| 195 | glo(tmp); |
| 196 | if((nfd = open(lock, O_CREAT | O_TRUNC | O_WRONLY, FMASK)) == -1) |
| 197 | panic("Cannot open temp file %s!\n", lock); |
| 198 | savelev(nfd,tmp); |
| 199 | (void) close(nfd); |
| 200 | } |
| 201 | (void) lseek(fd, (off_t)0, SEEK_SET); |
| 202 | getlev(fd, 0, 0); |
| 203 | (void) close(fd); |
| 204 | (void) unlink(SAVEF); |
| 205 | if(Punished) { |
| 13 | | Assuming field 'p_flgs' is 0 | |
|
| |
| 206 | for(otmp = fobj; otmp; otmp = otmp->nobj) |
| 207 | if(otmp->olet == CHAIN_SYM) goto chainfnd; |
| 208 | panic("Cannot find the iron chain?"); |
| 209 | chainfnd: |
| 210 | uchain = otmp; |
| 211 | if(!uball){ |
| 212 | for(otmp = fobj; otmp; otmp = otmp->nobj) |
| 213 | if(otmp->olet == BALL_SYM && otmp->spe) |
| 214 | goto ballfnd; |
| 215 | panic("Cannot find the iron ball?"); |
| 216 | ballfnd: |
| 217 | uball = otmp; |
| 218 | } |
| 219 | } |
| 220 | if(u.ustuck) { |
| 15 | | Assuming field 'ustuck' is non-null | |
|
| |
| 221 | struct monst *mtmp; |
| 222 | |
| 223 | for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) |
| 17 | | Loop condition is true. Entering loop body | |
|
| 224 | if(mtmp->m_id == mid) goto monfnd; |
| 18 | | The right operand of '==' is a garbage value |
|
| 225 | panic("Cannot find the monster ustuck."); |
| 226 | monfnd: |
| 227 | u.ustuck = mtmp; |
| 228 | } |
| 229 | #ifndef QUEST |
| 230 | setsee(); |
| 231 | #endif /* QUEST */ |
| 232 | docrt(); |
| 233 | restoring = FALSE; |
| 234 | return(1); |
| 235 | } |
| 236 | |
| 237 | struct obj * |
| 238 | restobjchn(int fd) |
| 239 | { |
| 240 | struct obj *otmp, *otmp2; |
| 241 | struct obj *first = 0; |
| 242 | int xl; |
| 243 | while(1) { |
| 244 | mread(fd, (char *) &xl, sizeof(xl)); |
| 245 | if(xl == -1) break; |
| 246 | otmp = newobj(xl); |
| 247 | if(!first) first = otmp; |
| 248 | else otmp2->nobj = otmp; |
| 249 | mread(fd, (char *) otmp, (unsigned) xl + sizeof(struct obj)); |
| 250 | if(!otmp->o_id) otmp->o_id = flags.ident++; |
| 251 | otmp2 = otmp; |
| 252 | } |
| 253 | if(first && otmp2->nobj){ |
| 254 | impossible("Restobjchn: error reading objchn."); |
| 255 | otmp2->nobj = 0; |
| 256 | } |
| 257 | return(first); |
| 258 | } |
| 259 | |
| 260 | struct monst * |
| 261 | restmonchn(int fd) |
| 262 | { |
| 263 | struct monst *mtmp, *mtmp2; |
| 264 | struct monst *first = 0; |
| 265 | int xl; |
| 266 | |
| 267 | struct permonst *monbegin; |
| 268 | long differ; |
| 269 | |
| 270 | mread(fd, (char *)&monbegin, sizeof(monbegin)); |
| 271 | differ = (char *)(&mons[0]) - (char *)(monbegin); |
| 272 | |
| 273 | while(1) { |
| 274 | mread(fd, (char *) &xl, sizeof(xl)); |
| 275 | if(xl == -1) break; |
| 276 | mtmp = newmonst(xl); |
| 277 | if(!first) first = mtmp; |
| 278 | else mtmp2->nmon = mtmp; |
| 279 | mread(fd, (char *) mtmp, (unsigned) xl + sizeof(struct monst)); |
| 280 | if(!mtmp->m_id) |
| 281 | mtmp->m_id = flags.ident++; |
| 282 | mtmp->data = (struct permonst *) |
| 283 | ((char *) mtmp->data + differ); |
| 284 | if(mtmp->minvent) |
| 285 | mtmp->minvent = restobjchn(fd); |
| 286 | mtmp2 = mtmp; |
| 287 | } |
| 288 | if(first && mtmp2->nmon){ |
| 289 | impossible("Restmonchn: error reading monchn."); |
| 290 | mtmp2->nmon = 0; |
| 291 | } |
| 292 | return(first); |
| 293 | } |