diff options
| author | Lexi Winter <ivy@FreeBSD.org> | 2026-08-03 14:09:39 +0000 |
|---|---|---|
| committer | Lexi Winter <ivy@FreeBSD.org> | 2026-08-03 14:09:39 +0000 |
| commit | 9f18614d5353ce513511ccbf59d09e76c93f7bc9 (patch) | |
| tree | da50db5e9304f01de3b214dd320c2e840394820c | |
| parent | 1d94e2e0f2ee21d5a4596efc0570d06e3dea0a6e (diff) | |
mandoc: Const correctness for C23
On some platforms, e.g. Linux Clang 22.1.8 / glibc 2.43, strchr()
now implements the C23 behaviour where passing a const pointer to
strchr() also returns a const pointer. This breaks mandoc during
the bootstrap build, since it assumes the return value is always
a mutable pointer.
In read.c, make the existing temporary pointer const, and for the
mandoc_asprintf() call, add a new mutable local.
In mdoc.c and out.c, since the data is mutable and is mutated here,
remove const from the temporary pointers.
MFC after: 1 week
Reviewed by: fuz
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D58495
| -rw-r--r-- | contrib/mandoc/mdoc.c | 3 | ||||
| -rw-r--r-- | contrib/mandoc/out.c | 4 | ||||
| -rw-r--r-- | contrib/mandoc/read.c | 10 |
3 files changed, 9 insertions, 8 deletions
diff --git a/contrib/mandoc/mdoc.c b/contrib/mandoc/mdoc.c index 475a6aa0ddb3..90a079870f64 100644 --- a/contrib/mandoc/mdoc.c +++ b/contrib/mandoc/mdoc.c @@ -165,8 +165,7 @@ static int mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs) { struct roff_node *n; - const char *cp, *sp; - char *c, *ws, *end; + char *c, *ws, *end, *cp, *sp; n = mdoc->last; diff --git a/contrib/mandoc/out.c b/contrib/mandoc/out.c index 21c282b2141b..082e7e61e8af 100644 --- a/contrib/mandoc/out.c +++ b/contrib/mandoc/out.c @@ -457,8 +457,8 @@ static size_t tblcalc_literal(struct rofftbl *tbl, struct roffcol *col, const struct tbl_dat *dp, size_t mw) { - const char *str; /* Beginning of the first line. */ - const char *beg; /* Beginning of the current line. */ + char *str; /* Beginning of the first line. */ + char *beg; /* Beginning of the current line. */ char *end; /* End of the current line. */ /* Widths in basic units. */ diff --git a/contrib/mandoc/read.c b/contrib/mandoc/read.c index 0e8d32df5a5e..d958a25832b3 100644 --- a/contrib/mandoc/read.c +++ b/contrib/mandoc/read.c @@ -628,7 +628,7 @@ mparse_readfd(struct mparse *curp, int fd, const char *filename) int mparse_open(struct mparse *curp, const char *file) { - char *cp; + const char *cp; int fd, save_errno; cp = strrchr(file, '.'); @@ -645,10 +645,12 @@ mparse_open(struct mparse *curp, const char *file) */ if ( ! curp->gzip) { + char *fn; + save_errno = errno; - mandoc_asprintf(&cp, "%s.gz", file); - fd = open(cp, O_RDONLY); - free(cp); + mandoc_asprintf(&fn, "%s.gz", file); + fd = open(fn, O_RDONLY); + free(fn); errno = save_errno; if (fd != -1) { curp->gzip = 1; |
