Re: small patch to suppress a warning

2021-02-16 Thread Niels Möller
Stephan Pleines  writes:

> So what is the verdict in this patch please?

Adding the pair of parentheses makes the code slightly more readable to
me. But it would still be nice if you could say what the warninsg
message to be suppressed is, and which compiler and version produces that
warning.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Limitation of the mpz_get_str function

2021-02-16 Thread Paul Zimmermann
   Hi Christophe,

this issue is known since several years:

https://gmplib.org/list-archives/gmp-bugs/2019-September/004633.html

Paul

> From: Christophe Clavier 
> Date: Tue, 16 Feb 2021 14:22:20 +0100
> 
> Dear GMP developers,
> 
> I currently have to deal with huge numbers (several billions decimal 
> digits) which I need to convert in strings of digits with mpz_get_str.
> I noticed that this function produces an incorrect result when the 
> number of digits exceeds 2^31.
> The reason lies in the loop that scans the buffer computed by 
> mpn_get_str and transforms each digit from an integer to an ascii code :
> 
>    for (i = 0; i < str_size; i++)
>      res_str[i] = num_to_text[(int) res_str[i]];
>    res_str[str_size] = 0;
> 
> As i is of type int, when it is incremented from 2^31-1 to 2^31 it 
> becomes negative.
> For the comparison with str_size, which is of type size_t (i.e. unsigned 
> long int), i is casted in unsigned long int and becomes a large positive 
> value near 2^64.
> Thus the comparison is evaluated to false and the loop early terminates.
> 
> I suggest to modify the type of i to long int or to unsigned long int.
> 
> Regards
> 
> Christophe
> 
> 
> ___
> gmp-bugs mailing list
> gmp-bugs@gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-bugs
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: Limitation of the mpz_get_str function

2021-02-16 Thread Vincent Lefevre
On 2021-02-16 14:22:20 +0100, Christophe Clavier wrote:
> I suggest to modify the type of i to long int or to unsigned long int.

long or unsigned long may still be on 32 bits, e.g. under MS Windows.

I think that a more appropriate type in the context of a string
(or more generally an array of char) would be size_t.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: small patch to suppress a warning

2021-02-16 Thread Stephan Pleines
So what is the verdict in this patch please?

On Thu, Feb 11, 2021 at 5:06 AM Hans Åberg  wrote:

>
> > On 11 Feb 2021, at 11:45, Torbjörn Granlund  wrote:
> >
> > I think there might be better places to discuss compiler warnings than
> > the gmp-bugs list.
> >
> > I think most of us agree that compiler warnings for valid C code are
> > sometimes useful.  For example, valid warnings about unitialised
> > variables seem pretty uncontroversial.
>
> Actually not, on Bison.
>
>
>
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Limitation of the mpz_get_str function

2021-02-16 Thread Christophe Clavier


Dear GMP developers,

I currently have to deal with huge numbers (several billions decimal 
digits) which I need to convert in strings of digits with mpz_get_str.
I noticed that this function produces an incorrect result when the 
number of digits exceeds 2^31.
The reason lies in the loop that scans the buffer computed by 
mpn_get_str and transforms each digit from an integer to an ascii code :


  for (i = 0; i < str_size; i++)
    res_str[i] = num_to_text[(int) res_str[i]];
  res_str[str_size] = 0;

As i is of type int, when it is incremented from 2^31-1 to 2^31 it 
becomes negative.
For the comparison with str_size, which is of type size_t (i.e. unsigned 
long int), i is casted in unsigned long int and becomes a large positive 
value near 2^64.

Thus the comparison is evaluated to false and the loop early terminates.

I suggest to modify the type of i to long int or to unsigned long int.

Regards

Christophe


___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs