~mcf/cproc

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] expr: fix erroneous comparison

Details
Message ID
<20220511152055.hfl4ueo5kmauvrso@gen2.localdomain>
DKIM signature
missing
Download raw message
Patch: +1 -1
as long as `size_t`'s conversion rank is >= `int` this check would work
out fine.

but in case size_t happens to be less than int (which I believe is valid
under the C standard) then comparison will take place in `signed int`
and the operand `-1` will not get implicitly converted to SIZE_MAX.

explicitly cast it to size_t to avoid such issues.
---
I suppose a cleaner solution could be to have something like
	#define UTF8DEC_ERR SIZE_MAX
and test against that instead. but utf8dec() seems to be only called in
this one place, so didn't think that was worth it.
 expr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/expr.c b/expr.c
index b43bff8..d2ba26e 100644
--- a/expr.c
+++ b/expr.c
@@ -403,7 +403,7 @@ decodechar(const char *src, uint_least32_t *chr, bool *hexoct, const char *desc,
		}
	} else {
		n = utf8dec(&c, s, 4);
		if (n == -1)
		if (n == (size_t)-1)
			error(loc, "%s contains invalid UTF-8", desc);
		s += n;
	}
-- 
2.35.1
Details
Message ID
<CAGw6cBtmLdHWfOyxdecNpBq6srKbPtvtQhHaqW9MuuDJXojNyw@mail.gmail.com>
In-Reply-To
<20220511152055.hfl4ueo5kmauvrso@gen2.localdomain> (view parent)
DKIM signature
missing
Download raw message
On 2022-05-22, NRK <nrk@disroot.org> wrote:
> as long as `size_t`'s conversion rank is >= `int` this check would work
> out fine.
>
> but in case size_t happens to be less than int (which I believe is valid
> under the C standard) then comparison will take place in `signed int`
> and the operand `-1` will not get implicitly converted to SIZE_MAX.
>
> explicitly cast it to size_t to avoid such issues.

Thanks for the patch, applied.

I'm not aware of any platforms where size_t is smaller than int, but
it doesn't hurt to fix it anyway :)
Reply to thread Export thread (mbox)