mandoc: Improve width calculation for GCC compat

Avoid implicitly converting a potentially negative page offset
to size_t and then back to int.  While this was not a bug and the end
result was portably correct, Alexander Ziaee@ privately reported to me
that the GCC 14 in the FreeBSD Jenkins CI felt uneasy about it.

For clarity and readability, rewrite the truncation statement
to not mix signed and unsigned types, to not use explicit casts,
and make handling of the lower and upper cutoff more similar
to each other.

Fixes:  6410c1b51637 (mandoc: vendor import of upstream at 2025-07-27)
MFC after:		3 days
Reported by:		ivy
Reviewed by:		ivy
Differential Revision:	https://reviews.freebsd.org/D52127
This commit is contained in:
Ingo Schwarze
2025-08-25 18:58:48 -04:00
committed by Alexander Ziaee
parent a4d738d783
commit 93bc3d83a1
+3 -2
View File
@@ -165,6 +165,7 @@ roff_term_pre_po(ROFF_TERM_ARGS)
static int polast; /* Previously requested. */
static int po; /* Currently requested. */
static int pouse; /* Currently used. */
int pomin; /* Minimum to be used. */
int pomax; /* Maximum to be used. */
int ponew; /* Newly requested. */
@@ -186,9 +187,9 @@ roff_term_pre_po(ROFF_TERM_ARGS)
po = ponew;
/* Truncate to the range [-offset, 60], remember, and apply it. */
pomin = -p->tcol->offset;
pomax = term_len(p, 60);
pouse = po >= pomax ? pomax :
po < -(int)p->tcol->offset ? -p->tcol->offset : po;
pouse = po > pomax ? pomax : po < pomin ? pomin : po;
p->tcol->offset += pouse;
}