bug in gmp_fprintf?
Vincent Lefevre
vincent at vinc17.net
Tue Dec 1 00:46:32 UTC 2015
On 2015-11-30 17:57:13 +0100, Torbjörn Granlund wrote:
> I should add that a big problem with gmp_*printf remains:
>
> When printing more than MAX_INT characters, the return value makes
> little sense.
C's printf has the same problem, in particular for GNU libc:
https://sourceware.org/bugzilla/show_bug.cgi?id=5424
(a bug I reported 8 years ago). This has been solved by returning
a negative value and setting errno to EOVERFLOW so that it is not
confused with a real error. However this is less a problem in the
standard printf because it does not have to deal with high-precision
numbers, so that in practice, there are workarounds to avoid this
overflow if one really wants to.
> In order to fix that, we need to change the return value of these
> functions from int to e.g. long. But that's a change which is not 100%
> source or binary compatible.
Alternatively, you could decide to return -1 in case of true error
and -2 in case of overflow on the return value (since you may not
want to use errno). To get the number of characters written, the
user could still use %n with an adequate length modifier, so that
there is no loss of information.
--
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