Re: printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)

2018-01-18 Thread sisyphus1
-Original Message- 
From: Vincent Lefevre

Sent: Friday, January 19, 2018 1:07 AM
To: sisyph...@optusnet.com.au ; paul zimmermann ; sav...@ukr.net ; 
gmp-bugs@gmplib.org

Subject: Re: printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)


printf/repl-vsnprintf.c seems buggy for floating-point specifiers
(EeGgFf). Replace "break" by "goto next" (2 occurrences)?


Proposed patch attached. Not tested.


Patch tests fine for me.

Cheers,
Rob


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


printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)

2018-01-18 Thread sav_ix




--- Оригінальне повідомлення ---
Від кого: "Vincent Lefevre" 
Дата: 18 січня 2018, 16:07:10


> Proposed patch attached. Not tested.


--- Оригінальне повідомлення ---
Від кого: "paul zimmermann" 
Дата: 18 січня 2018, 16:16:44


> here is a test case to reproduce the issue (you have to test it on a system 
> that
> doesn't have vsnprintf, or only has a broken one, or define HAVE_VSNPRINTF to 
> 0 in
> config.h):

and '--enable-assert' flag should be used for GMP build.



Using Paul's testcase and Vincent's patch got results:

1. For builds using mingw-w64 without '__USE_MINGW_ANSI_STDIO' flag (which 
targets 'msvcrt.dll' with broken 'vsnprintf()', 
seehttps://github.com/msys2/msys2/wiki/Porting#c-printf-format-specifier-issues):

  a) testcase output:
    - for vanilla GMP sources:
===
c:\test>gcc gmp_vsnprintf_test.c -I. -L. -lgmp && a.exe
repl-vsnprintf.c:357: GNU MP assertion failed: 0

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
=== 

    - for patched GMP sources:
===
c:\test>gcc gmp_vsnprintf_test.c -I. -L. -lgmp && a.exe
size=12 s='17.00 42'
=== 

  b) MPFR testsuite summary:
    - for vanilla GMP sources:
for vanilla GMP 
sources:===
...
FAIL: tfprintf.exe
...
FAIL: tprintf.exe
...
FAIL: tsprintf.exe
...

Testsuite summary for MPFR 4.1.0-dev

# TOTAL: 180
# PASS:  177
# SKIP:  0
# XFAIL: 0
# FAIL:  3
# XPASS: 0
# ERROR: 0

=== 

    - for patched GMP sources:
===

Testsuite summary for MPFR 4.1.0-dev

# TOTAL: 180
# PASS:  180
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0

=== 


2. For builds using MSVC (which targets 'ucrtbase.dll' with broken 
'vsnprintf()', see 
https://developercommunity.visualstudio.com/content/problem/168219/incomplete-ansi-c99-stdio-support-in-windows-sdk.html):

  a) testcase output:
    - for vanilla GMP sources:
===
c:\test>cl gmp_vsnprintf_test.c -I. -MDd gmp.lib && gmp_vsnprintf_test.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.12.25830.2 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

gmp_vsnprintf_test.c
Microsoft (R) Incremental Linker Version 14.12.25830.2
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:gmp_vsnprintf_test.exe
gmp_vsnprintf_test.obj
gmp.lib
repl-vsnprintf.c:357: GNU MP assertion failed: 0
=== 

    - for patched GMP sources:
===
c:\test>cl gmp_vsnprintf_test.c -I. -MDd gmp.lib && gmp_vsnprintf_test.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.12.25830.2 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

gmp_vsnprintf_test.c
Microsoft (R) Incremental Linker Version 14.12.25830.2
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:gmp_vsnprintf_test.exe
gmp_vsnprintf_test.obj
gmp.lib
size=12 s='17.00 42'
=== 

    b) MPFR testsuite summary:
    - for vanilla GMP sources:
for vanilla GMP 
sources:===
...
FAIL: tfprintf.exe
...
FAIL: tprintf.exe
...
FAIL: tsprintf.exe
...

Testsuite summary for MPFR 4.1.0-dev

# TOTAL: 180
# PASS:  174
# SKIP:  3
# XFAIL: 0
# FAIL:  3
# XPASS: 0
# ERROR: 0

=== 

    - for patched GMP sources:
===

Testsuite summary for MPFR 4.1.0-dev

# TOTAL: 180
# PASS:  177
# SKIP:  3
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERRO

Re: printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)

2018-01-18 Thread paul zimmermann
it should be noted that this bug was not found by GMP's "make check"
(to my best knowledge), but only by MPFR's test suite.

Before fixing the bug, it would be nice to fix the GMP test suite.

Paul

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


Re: printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)

2018-01-18 Thread paul zimmermann
> > printf/repl-vsnprintf.c seems buggy for floating-point specifiers
> > (EeGgFf). Replace "break" by "goto next" (2 occurrences)?
> 
> Proposed patch attached. Not tested.

here is a test case to reproduce the issue (you have to test it on a system that
doesn't have vsnprintf, or only has a broken one, or define HAVE_VSNPRINTF to 0 
in
config.h):

#define _GNU_SOURCE
#include 
#include 
#include 
#include 

int test(const char *fmt,...)
{
  va_list args;
  char *s = NULL;
  int size;

  va_start(args,fmt);
  size = gmp_vasprintf(&s, fmt, args);
  printf("size=%d s='%s'\n", size, s);

  return 0;
}

int main(void)
{
  char *fmt = "%f %Zd";
  mpz_t z;
  float f = 17.0;
  mpz_init_set_ui (z, 42);
  test(fmt, f, z);
  mpz_clear (z);
}

$ ./a.out 
repl-vsnprintf.c:358: GNU MP assertion failed: 0
Aborted (core dumped)

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


Re: printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)

2018-01-18 Thread Vincent Lefevre
On 2018-01-18 14:16:41 +0100, Vincent Lefevre wrote:
> [Cc to gmp-bugs]
> 
> On 2018-01-18 23:14:12 +1100, sisyph...@optusnet.com.au wrote:
> > Just had a reply on the mingw64 mailing list.
> > Apparently, the test programs are not crashing - abort() is being called
> > following an assertion failure.
> > And this calls for a "break abort" prior to "run" being called.
> > 
> > See attached backtrace for tfprintf.exe. (I could supply equivalent for the
> > other 2 failing test programs - but I think they're essentially the same.)
> 
> printf/repl-vsnprintf.c seems buggy for floating-point specifiers
> (EeGgFf). Replace "break" by "goto next" (2 occurrences)?

Proposed patch attached. Not tested.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
diff -r bd031c4d736b printf/repl-vsnprintf.c
--- a/printf/repl-vsnprintf.c   Wed Jan 17 05:34:55 2018 +0100
+++ b/printf/repl-vsnprintf.c   Thu Jan 18 15:05:49 2018 +0100
@@ -243,7 +243,7 @@
  }
else
  (void) va_arg (ap, double);
-   break;
+   goto next;
 
  case 'f':
/* Requested decimals, sign and point, and a margin for error,
@@ -264,7 +264,7 @@
(void) va_arg (ap, double);
total_width += double_digits;
  }
-   break;
+   goto next;
 
  case 'h':  /* short or char */
  case 'j':  /* intmax_t */
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


printf/repl-vsnprintf.c bug (was: GMP|MPIR|MPFR assertions)

2018-01-18 Thread Vincent Lefevre
[Cc to gmp-bugs]

On 2018-01-18 23:14:12 +1100, sisyph...@optusnet.com.au wrote:
> Just had a reply on the mingw64 mailing list.
> Apparently, the test programs are not crashing - abort() is being called
> following an assertion failure.
> And this calls for a "break abort" prior to "run" being called.
> 
> See attached backtrace for tfprintf.exe. (I could supply equivalent for the
> other 2 failing test programs - but I think they're essentially the same.)

printf/repl-vsnprintf.c seems buggy for floating-point specifiers
(EeGgFf). Replace "break" by "goto next" (2 occurrences)?

-- 
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