undefined behavior in GMP 5.1.2
Marc Glisse
marc.glisse at inria.fr
Sat Sep 21 11:15:01 CEST 2013
On Sat, 21 Sep 2013, Vincent Lefevre wrote:
> t-mulmid.c:81:11: warning: format specifies type 'int' but the argument has type 'mp_size_t' (aka 'long') [-Wformat]
> test, an, bn, rn);
> ^~
> t-mulmid.c:81:15: warning: format specifies type 'int' but the argument has type 'mp_size_t' (aka 'long') [-Wformat]
> test, an, bn, rn);
> ^~
> t-mulmid.c:81:19: warning: format specifies type 'int' but the argument has type 'mp_size_t' (aka 'long') [-Wformat]
> test, an, bn, rn);
> ^~
> for
> printf ("ERROR in test %d, an = %d, bn = %d, rn = %d\n",
> test, an, bn, rn);
>
> This is really a bug.
I think an, bn, rn can't be large in this test so we can just cast them to
int.
> In tests/mpz/t-mfac_uiui.c, this is a potential bug (replace & by %
> I suppose):
>
> t-mfac_uiui.c:69:55: warning: data argument not used by format string [-Wformat-extra-args]
> printf ("mpz_mfac_uiui(%lu,&i) wrong\n", n, MULTIFAC_WHEEL);
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
Looks like a typo, and it is already fixed. It would have been more useful
to test more current sources.
> kronzs.c:53:28: runtime error: negation of -9223372036854775808 cannot be represented in type 'long'; cast to an unsigned type to negate this value to itself
> FAIL: t-jac
>
> get_d.c:137:7: runtime error: signed integer overflow: 9223372036854775807 - -2 cannot be represented in type 'long'
> FAIL: t-get_d_2exp
Those last 2 have been fixed since June.
> t-urbui.c:38:19: runtime error: left shift of 1 by 63 places cannot be represented in type 'long'
> FAIL: t-urbui
s/1L/1UL/ that one is easy :-)
So it leaves these 2 that I haven't really looked at:
> get_str.c:538:52: runtime error: index -1 out of bounds for type 'powers_t [64]'
> FAIL: convert
> mul.c:81:31: runtime error: signed integer overflow: -5260204364771764878 + -5260204364771764878 cannot be represented in type 'long'
> FAIL: reuse
Thanks,
--
Marc Glisse
More information about the gmp-bugs
mailing list