Print this page
9718 update mandoc to 1.14.4

*** 1,9 **** ! /* $Id: read.c,v 1.192 2017/07/20 14:36:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> ! * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. --- 1,9 ---- ! /* $Id: read.c,v 1.196 2018/07/28 18:34:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> ! * Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies.
*** 92,113 **** "referenced manual not found", "generic style suggestion", "legacy man(7) date format", "lower case character in document title", "duplicate RCS id", ! "typo in section name", "unterminated quoted argument", "useless macro", "consider using OS macro", "errnos out of order", "duplicate errno", "trailing delimiter", "no blank before trailing delimiter", "fill mode already enabled, skipping", "fill mode already disabled, skipping", "function name without markup", "whitespace at end of input line", "bad comment style", "generic warning", --- 92,115 ---- "referenced manual not found", "generic style suggestion", "legacy man(7) date format", + "normalizing date format to", "lower case character in document title", "duplicate RCS id", ! "possible typo in section name", "unterminated quoted argument", "useless macro", "consider using OS macro", "errnos out of order", "duplicate errno", "trailing delimiter", "no blank before trailing delimiter", "fill mode already enabled, skipping", "fill mode already disabled, skipping", + "verbatim \"--\", maybe consider using \\(em", "function name without markup", "whitespace at end of input line", "bad comment style", "generic warning",
*** 554,563 **** --- 556,566 ---- { struct stat st; gzFile gz; size_t off; ssize_t ssz; + int gzerrnum, retval; if (fstat(fd, &st) == -1) { mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, "fstat: %s", strerror(errno)); return 0;
*** 581,593 **** --- 584,609 ---- if (fb->buf != MAP_FAILED) return 1; } if (curp->gzip) { + /* + * Duplicating the file descriptor is required + * because we will have to call gzclose(3) + * to free memory used internally by zlib, + * but that will also close the file descriptor, + * which this function must not do. + */ + if ((fd = dup(fd)) == -1) { + mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, + "dup: %s", strerror(errno)); + return 0; + } if ((gz = gzdopen(fd, "rb")) == NULL) { mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, "gzdopen: %s", strerror(errno)); + close(fd); return 0; } } else gz = NULL;
*** 596,605 **** --- 612,622 ---- * go the old way and just read things in bit by bit. */ *with_mmap = 0; off = 0; + retval = 0; fb->sz = 0; fb->buf = NULL; for (;;) { if (off == fb->sz) { if (fb->sz == (1U << 31)) {
*** 612,634 **** ssz = curp->gzip ? gzread(gz, fb->buf + (int)off, fb->sz - off) : read(fd, fb->buf + (int)off, fb->sz - off); if (ssz == 0) { fb->sz = off; ! return 1; } if (ssz == -1) { ! mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, ! "read: %s", strerror(errno)); break; } off += (size_t)ssz; } free(fb->buf); fb->buf = NULL; ! return 0; } static void mparse_end(struct mparse *curp) { --- 629,661 ---- ssz = curp->gzip ? gzread(gz, fb->buf + (int)off, fb->sz - off) : read(fd, fb->buf + (int)off, fb->sz - off); if (ssz == 0) { fb->sz = off; ! retval = 1; ! break; } if (ssz == -1) { ! if (curp->gzip) ! (void)gzerror(gz, &gzerrnum); ! mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, "read: %s", ! curp->gzip && gzerrnum != Z_ERRNO ? ! zError(gzerrnum) : strerror(errno)); break; } off += (size_t)ssz; } + if (curp->gzip && (gzerrnum = gzclose(gz)) != Z_OK) + mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, "gzclose: %s", + gzerrnum == Z_ERRNO ? strerror(errno) : + zError(gzerrnum)); + if (retval == 0) { free(fb->buf); fb->buf = NULL; ! } ! return retval; } static void mparse_end(struct mparse *curp) {