=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/roff.c,v retrieving revision 1.253 retrieving revision 1.254 diff -u -r1.253 -r1.254 --- src/usr.bin/mandoc/roff.c 2022/04/13 13:11:33 1.253 +++ src/usr.bin/mandoc/roff.c 2022/04/24 13:34:53 1.254 @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.253 2022/04/13 13:11:33 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.254 2022/04/24 13:34:53 schwarze Exp $ */ /* * Copyright (c) 2010-2015, 2017-2022 Ingo Schwarze * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons @@ -3868,8 +3868,9 @@ roff_shift(ROFF_ARGS) { struct mctx *ctx; - int levels, i; + int argpos, levels, i; + argpos = pos; levels = 1; if (buf->buf[pos] != '\0' && roff_evalnum(r, ln, buf->buf, &pos, &levels, 0) == 0) { @@ -3884,8 +3885,12 @@ ctx = r->mstack + r->mstackpos; if (levels > ctx->argc) { mandoc_msg(MANDOCERR_SHIFT, - ln, pos, "%d, but max is %d", levels, ctx->argc); + ln, argpos, "%d, but max is %d", levels, ctx->argc); levels = ctx->argc; + } + if (levels < 0) { + mandoc_msg(MANDOCERR_ARG_NEG, ln, argpos, "shift %d", levels); + levels = 0; } if (levels == 0) return ROFF_IGN;