with strict C99 the tests/mpz/convert.c needs #include <strings.h>

Vincent Lefevre vincent at vinc17.net
Tue Nov 10 14:21:38 UTC 2020


On 2020-11-09 10:14:37 +0100, Torbjorn Granlund wrote:
> Vincent Lefevre <vincent at vinc17.net> writes:
> 
>   In the context of the call, the values will always be nonnegative
>   so that this is OK, but there is a risk that some future developer
>   might reuse this function in another context, where it would be
>   incorrect on platforms with signed char (in particular, there is
>   no warning in the comment).
> 
> Perhaps we could rename this function
> note_that_this_funtion_is_called_str_casecmp_and_not_strcasecmp, to
> avoid such looming disaster?  Or, to be more polite, perhaps
> please_note_that_this_funtion_is_called_str_casecmp_and_not_strcasecmp?

Since GMP developers are so smart, why does the test exist anyway?
Since GMP is expected to return the correct answer, it is not needed
to do the test.

Seriously, this function is used in a context to test the result of
mpz_get_str, and it is better to assume any kind of bug (which could
come from GMP or the compiler, for instance). In particular, do not
assume that the string returned by mpz_get_str necessarily consists
of valid digits. The consequence of a bug might be that some memory
location in the string is an invalid digit or is not explicitly set.
If this happens, the test tolower (c1) != tolower (c2) may be false
in such a case, so that the error may remain undetected. Something
like

  if (c1 < 0 || c2 < 0)
    abort ();

would improve the test.

Moreover, there's something I don't understand. In the test,

   base = bsi % 62 + 1;

so that the base may be larger or equal to 37, but in such bases,
the case is significant, but it is not tested. I mean that with the
current test, you won't be able to distinguish "1a" from "1A".

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-bugs mailing list