diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-08-26 20:38:14 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-08-26 20:38:14 +0000 |
commit | 7f98abb96223e9feb966ec08b88dfec8aa50d4fc (patch) | |
tree | 5d130d7f02cddea31ed59f9e70535947d54e8258 | |
parent | c91da7a12ce9c35b28b6bd3cb716a459222cf57d (diff) | |
download | mandoc-7f98abb96223e9feb966ec08b88dfec8aa50d4fc.tar.gz |
Fix previous: mmap(2) returns MAP_FAILED on failure, not NULL.
Bug pointed out by tedu@.
-rw-r--r-- | mandocdb.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -2152,7 +2152,7 @@ dbwrite(struct dba *dba) say("", "&%s", tfn); return; } - cp1 = cp2 = NULL; + cp1 = cp2 = MAP_FAILED; fd1 = fd2 = -1; (void)strlcat(tfn, "/" MANDOC_DB, sizeof(tfn)); if (dba_write(tfn, dba) == -1) { @@ -2178,12 +2178,12 @@ dbwrite(struct dba *dba) if (sb1.st_size != sb2.st_size) goto err; if ((cp1 = mmap(NULL, sb1.st_size, PROT_READ, MAP_PRIVATE, - fd1, 0)) == NULL) { + fd1, 0)) == MAP_FAILED) { say(MANDOC_DB, "&mmap"); goto err; } if ((cp2 = mmap(NULL, sb2.st_size, PROT_READ, MAP_PRIVATE, - fd2, 0)) == NULL) { + fd2, 0)) == MAP_FAILED) { say(tfn, "&mmap"); goto err; } @@ -2197,9 +2197,9 @@ err: say(MANDOC_DB, "Data changed, but cannot replace database"); out: - if (cp1 != NULL) + if (cp1 != MAP_FAILED) munmap(cp1, sb1.st_size); - if (cp2 != NULL) + if (cp2 != MAP_FAILED) munmap(cp2, sb2.st_size); if (fd1 != -1) close(fd1); |