From d7fd90d22da38356ab7e1c4509d471b56e47bc41 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 31 May 2025 18:17:34 -0700 Subject: [PATCH] =?utf8?q?factor:=20don=E2=80=99t=20used=20uninitialized?= =?utf8?q?=20uu[0]?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In practice there’s no bug but we might as well avoid the undefined behavior. * src/factor.c (hi_is_set): New static function. (factor_insert_large, prime2_p, print_factors_single): Use it. --- src/factor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/factor.c b/src/factor.c index 948bf05274..ff9d3c0be3 100644 --- a/src/factor.c +++ b/src/factor.c @@ -236,6 +236,7 @@ typedef struct { wide_uint uu[2]; } uuint; static wide_uint lo (uuint u) { return u.uu[0]; } static wide_uint hi (uuint u) { return u.uu[1]; } static void hiset (uuint *u, wide_uint hi) { u->uu[1] = hi; } +static bool hi_is_set (uuint const *pu) { return pu->uu[1] != 0; } static void uuset (wide_uint *phi, wide_uint *plo, uuint uu) { @@ -557,7 +558,7 @@ factor_insert_large (struct factors *factors, { if (p1 > 0) { - affirm (hi (factors->plarge) == 0); + affirm (!hi_is_set (&factors->plarge)); factors->plarge = make_uuint (p1, p0); } else @@ -1335,7 +1336,7 @@ prime2_p (wide_uint n1, wide_uint n0) if (flag_prove_primality) { is_prime = true; - if (hi (factors.plarge)) + if (hi_is_set (&factors.plarge)) { wide_uint pi; binv (pi, lo (factors.plarge)); @@ -2510,7 +2511,7 @@ print_factors_single (wide_uint t1, wide_uint t0) } } - if (hi (factors.plarge)) + if (hi_is_set (&factors.plarge)) { lbuf_putc (' '); print_uuint (factors.plarge); -- 2.47.3