<feed xmlns='http://www.w3.org/2005/Atom'>
<title>gcc.git/libquadmath/printf/printf_fp.c, branch master</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/'/>
<entry>
<title>libquadmath: Don't assume the storage for __float128 arguments is aligned [PR114533]</title>
<updated>2024-04-03T08:13:40+00:00</updated>
<author>
<name>Jakub Jelinek</name>
<email>jakub@redhat.com</email>
</author>
<published>2024-04-03T08:02:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=8455d6f6cd43b7b143ab9ee19437452fceba9cc9'/>
<id>8455d6f6cd43b7b143ab9ee19437452fceba9cc9</id>
<content type='text'>
With the register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided with
a callback to fetch the argument from va_list using va_arg into C library provided
memory.  The C library isn't told what alignment requirement it has, but we were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.

The following patch fixes that by using memcpy instead.

I haven't been able to reproduce an actual crash, tried
 #include &lt;quadmath.h&gt;
 #include &lt;stdlib.h&gt;
 #include &lt;stdio.h&gt;

int main ()
{
  __float128 r;
  int prec = 20;
  int width = 46;
  char buf[128];

  r = 2.0q;
  r = sqrtq (r);
  int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
  if ((size_t) n &lt; sizeof buf)
    printf ("%s\n", buf);
    /* Prints: +1.41421356237309504880e+00 */
  quadmath_snprintf (buf, sizeof buf, "%Qa", r);
  if ((size_t) n &lt; sizeof buf)
    printf ("%s\n", buf);
    /* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
  n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
  if (n &gt; -1)
    {
      char *str = malloc (n + 1);
      if (str)
        {
          quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
          printf ("%s\n", str);
          /* Prints: +1.41421356237309504880e+00 */
        }
      free (str);
    }
  printf ("%+-#*.20Qe\n", width, r);
  printf ("%Qa\n", r);
  printf ("%+-#46.*Qe\n", prec, r);
  printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
  return 0;
}
In any case, I think memcpy for loading from it is right.

2024-04-03  Simon Chopin  &lt;simon.chopin@canonical.com&gt;
	    Jakub Jelinek  &lt;jakub@redhat.com&gt;

	PR libquadmath/114533
	* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
	__float128 out of args.
	* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.

Signed-off-by: Simon Chopin &lt;simon.chopin@canonical.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With the register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided with
a callback to fetch the argument from va_list using va_arg into C library provided
memory.  The C library isn't told what alignment requirement it has, but we were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.

The following patch fixes that by using memcpy instead.

I haven't been able to reproduce an actual crash, tried
 #include &lt;quadmath.h&gt;
 #include &lt;stdlib.h&gt;
 #include &lt;stdio.h&gt;

int main ()
{
  __float128 r;
  int prec = 20;
  int width = 46;
  char buf[128];

  r = 2.0q;
  r = sqrtq (r);
  int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
  if ((size_t) n &lt; sizeof buf)
    printf ("%s\n", buf);
    /* Prints: +1.41421356237309504880e+00 */
  quadmath_snprintf (buf, sizeof buf, "%Qa", r);
  if ((size_t) n &lt; sizeof buf)
    printf ("%s\n", buf);
    /* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
  n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
  if (n &gt; -1)
    {
      char *str = malloc (n + 1);
      if (str)
        {
          quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
          printf ("%s\n", str);
          /* Prints: +1.41421356237309504880e+00 */
        }
      free (str);
    }
  printf ("%+-#*.20Qe\n", width, r);
  printf ("%Qa\n", r);
  printf ("%+-#46.*Qe\n", prec, r);
  printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
  return 0;
}
In any case, I think memcpy for loading from it is right.

2024-04-03  Simon Chopin  &lt;simon.chopin@canonical.com&gt;
	    Jakub Jelinek  &lt;jakub@redhat.com&gt;

	PR libquadmath/114533
	* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
	__float128 out of args.
	* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.

Signed-off-by: Simon Chopin &lt;simon.chopin@canonical.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Revert libquadmath and libssp copyright patches.</title>
<updated>2013-02-06T22:03:54+00:00</updated>
<author>
<name>Richard Sandiford</name>
<email>rdsandiford@googlemail.com</email>
</author>
<published>2013-02-06T22:03:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=1b78544ffe0cdca95b935ca740efb5919a2b72e9'/>
<id>1b78544ffe0cdca95b935ca740efb5919a2b72e9</id>
<content type='text'>
From-SVN: r195820
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
From-SVN: r195820
</pre>
</div>
</content>
</entry>
<entry>
<title>Update copyright in libquadmath.</title>
<updated>2013-02-03T17:49:30+00:00</updated>
<author>
<name>Richard Sandiford</name>
<email>rdsandiford@googlemail.com</email>
</author>
<published>2013-02-03T17:49:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=1a41c323b040bf5739dcb9cb9893b30f0a814df8'/>
<id>1a41c323b040bf5739dcb9cb9893b30f0a814df8</id>
<content type='text'>
From-SVN: r195699
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
From-SVN: r195699
</pre>
</div>
</content>
</entry>
<entry>
<title>quadmath-rounding-mode.h: New.</title>
<updated>2012-11-23T22:11:40+00:00</updated>
<author>
<name>Tobias Burnus</name>
<email>burnus@net-b.de</email>
</author>
<published>2012-11-23T22:11:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=05abb346d6b987349780c79e45530d88fcebccf4'/>
<id>05abb346d6b987349780c79e45530d88fcebccf4</id>
<content type='text'>
2012-11-23  Tobias Burnus  &lt;burnus@net-b.de&gt;
            Joseph Myers  &lt;joseph@codesourcery.com&gt;

        * quadmath-rounding-mode.h: New.
        * printf/fpioconst.c: Update from GLIBC. Fix strtod rounding.
        * printf/fpioconst.h: Ditto.
        * printf/printf_fp.c (__quadmath_printf_fp): Update from GLIBC.
        Make printf respect the rounding mode for decimal output.
        * printf/printf_fphex.c (__quadmath_printf_fphex): Update from
        GLIBC.  Make printf respect the rounding mode for hex output.
        * strtod/strtod_l.c: Update from GLIBC. Make strtod respect the
        rounding mode. Fix strtod handling of underflow.


Co-Authored-By: Joseph Myers &lt;joseph@codesourcery.com&gt;

From-SVN: r193770
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
2012-11-23  Tobias Burnus  &lt;burnus@net-b.de&gt;
            Joseph Myers  &lt;joseph@codesourcery.com&gt;

        * quadmath-rounding-mode.h: New.
        * printf/fpioconst.c: Update from GLIBC. Fix strtod rounding.
        * printf/fpioconst.h: Ditto.
        * printf/printf_fp.c (__quadmath_printf_fp): Update from GLIBC.
        Make printf respect the rounding mode for decimal output.
        * printf/printf_fphex.c (__quadmath_printf_fphex): Update from
        GLIBC.  Make printf respect the rounding mode for hex output.
        * strtod/strtod_l.c: Update from GLIBC. Make strtod respect the
        rounding mode. Fix strtod handling of underflow.


Co-Authored-By: Joseph Myers &lt;joseph@codesourcery.com&gt;

From-SVN: r193770
</pre>
</div>
</content>
</entry>
<entry>
<title>printf_fp.c (__quadmath_printf_fp): Use memcpy instead of mempcpy.</title>
<updated>2011-03-25T20:12:37+00:00</updated>
<author>
<name>Jakub Jelinek</name>
<email>jakub@redhat.com</email>
</author>
<published>2011-03-25T20:12:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=cf3b3080558eb84d79b0dfe73683c7d2b65bb3ac'/>
<id>cf3b3080558eb84d79b0dfe73683c7d2b65bb3ac</id>
<content type='text'>
	* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy instead of
	mempcpy.

From-SVN: r171525
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy instead of
	mempcpy.

From-SVN: r171525
</pre>
</div>
</content>
</entry>
<entry>
<title>quadmath-printf.c: Also check __GLIBC__ when checking whether workarounds for printf hook handling...</title>
<updated>2011-02-16T13:54:30+00:00</updated>
<author>
<name>Jakub Jelinek</name>
<email>jakub@redhat.com</email>
</author>
<published>2011-02-16T13:54:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=d2995f218548fb6e506348377bf150c69dd231a6'/>
<id>d2995f218548fb6e506348377bf150c69dd231a6</id>
<content type='text'>
	* printf/quadmath-printf.c: Also check __GLIBC__ when checking
	whether workarounds for printf hook handling should be added.

	* configure.ac: Check for locale.h too.
	(USE_LOCALE_SUPPORT): Remove check.
	(USE_NL_LANGINFO, USE_NL_LANGINFO_WC, USE_LOCALECONV): New checks.
	(USE_I18_NUMBER_H): Check also for _NL_CTYPE_MB_CUR_MAX.
	* printf/printf_fphex.c (__quadmath_printf_fphex): Use nl_langinfo
	or localeconv for narrow version and nl_langinfo if USE_NL_LANGINFO_WC
	for wide version.
	* printf/quadmath-printf.h: Include locale.h if HAVE_LOCALE_H.
	* printf/printf_fp.c (USE_I18N_NUMBER_H): Don't define to 0.
	(__quadmath_printf_fp): Use nl_langinfo or localeconv for narrow
	version and nl_langinfo if USE_NL_LANGINFO_WC for wide version.
	Guard nl_langinfo (_NL_CTYPE_MB_CUR_MAX) use with
	USE_I18N_NUMBER_H #ifdef.
	* configure: Regenerated.
	* config.h.in: Regenerated.

From-SVN: r170211
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	* printf/quadmath-printf.c: Also check __GLIBC__ when checking
	whether workarounds for printf hook handling should be added.

	* configure.ac: Check for locale.h too.
	(USE_LOCALE_SUPPORT): Remove check.
	(USE_NL_LANGINFO, USE_NL_LANGINFO_WC, USE_LOCALECONV): New checks.
	(USE_I18_NUMBER_H): Check also for _NL_CTYPE_MB_CUR_MAX.
	* printf/printf_fphex.c (__quadmath_printf_fphex): Use nl_langinfo
	or localeconv for narrow version and nl_langinfo if USE_NL_LANGINFO_WC
	for wide version.
	* printf/quadmath-printf.h: Include locale.h if HAVE_LOCALE_H.
	* printf/printf_fp.c (USE_I18N_NUMBER_H): Don't define to 0.
	(__quadmath_printf_fp): Use nl_langinfo or localeconv for narrow
	version and nl_langinfo if USE_NL_LANGINFO_WC for wide version.
	Guard nl_langinfo (_NL_CTYPE_MB_CUR_MAX) use with
	USE_I18N_NUMBER_H #ifdef.
	* configure: Regenerated.
	* config.h.in: Regenerated.

From-SVN: r170211
</pre>
</div>
</content>
</entry>
<entry>
<title>configure.ac (HAVE_HIDDEN_VISIBILITY): Test with -Werror in CFLAGS.</title>
<updated>2011-02-14T16:40:38+00:00</updated>
<author>
<name>Jakub Jelinek</name>
<email>jakub@redhat.com</email>
</author>
<published>2011-02-14T16:40:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=49f0e1ba4aa0eafe931e34a0876be7b8df58afde'/>
<id>49f0e1ba4aa0eafe931e34a0876be7b8df58afde</id>
<content type='text'>
	* configure.ac (HAVE_HIDDEN_VISIBILITY): Test with -Werror in CFLAGS.
	* printf/printf_fp.c: Don't include &lt;alloca.h&gt;.
	* printf/quadmath-printf.h (_itoa): Redefine to __quadmath_itoa.
	* configure: Regenerated.

From-SVN: r170139
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	* configure.ac (HAVE_HIDDEN_VISIBILITY): Test with -Werror in CFLAGS.
	* printf/printf_fp.c: Don't include &lt;alloca.h&gt;.
	* printf/quadmath-printf.h (_itoa): Redefine to __quadmath_itoa.
	* configure: Regenerated.

From-SVN: r170139
</pre>
</div>
</content>
</entry>
<entry>
<title>re PR fortran/47642 (real(kind=16) - libquadmath - segfault on amd64 FreeBSD)</title>
<updated>2011-02-14T15:34:44+00:00</updated>
<author>
<name>Jakub Jelinek</name>
<email>jakub@redhat.com</email>
</author>
<published>2011-02-14T15:34:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/gcc.git/commit/?id=1d92226be3a775b085e90436067c45f938fba761'/>
<id>1d92226be3a775b085e90436067c45f938fba761</id>
<content type='text'>
	PR fortran/47642
	* libquadmath.texi (quadmath_snprintf): Document.
	(quadmath_flt128tostr): Remove.
	* Makefile.am (libquadmath_la_SOURCES): Add printf/*.c.
	Remove  quadmath_io.c, gdtoa/gdtoa.c, gdtoa/g__fmt.c,
	gdtoa/g_Qfmt.c, gdtoa/dmisc.c and gdtoa/ulp.c.
	* quadmath.h (quadmath_snprintf): New prototype.
	(quadmath_flt128tostr): Remove.
	* quadmath_weak.h (quadmath_snprintf): Add.
	(quadmath_flt128tostr): Remove.
	* configure.ac: New AC_CHECK_HEADERS headers: langinfo.h, wchar.h,
	wctype.h, limits.h, ctype.h, printf.h, errno.h.
	(AC_USE_SYSTEM_EXTENSIONS): Add.
	(HAVE_HIDDEN_VISIBILITY, HAVE_PRINTF_HOOKS,
	USE_LOCALE_SUPPORT, USE_I18N_NUMBER_H): New checks.
	* quadmath.map (QUADMATH_1.0): Add quadmath_snprintf.  Remove
	quadmath_flt128tostr.
	* printf/printf_fphex.c: New file.
	* printf/_itowa.h: New file.
	* printf/mul_n.c: New file.
	* printf/quadmath-printf.h: New file.
	* printf/submul_1.c: New file.
	* printf/quadmath-printf.c: New file.
	* printf/gmp-impl.h: New file.
	* printf/lshift.c: New file.
	* printf/fpioconst.h: New file.
	* printf/add_n.c: New file.
	* printf/cmp.c: New file.
	* printf/sub_n.c: New file.
	* printf/mul.c: New file.
	* printf/divrem.c: New file.
	* printf/addmul_1.c: New file.
	* printf/printf_fp.c: New file.
	* printf/_itoa.h: New file.
	* printf/fpioconst.c: New file.
	* printf/_i18n_number.h: New file.
	* printf/flt1282mpn.c: New file.
	* printf/rshift.c: New file.
	* printf/mul_1.c: New file.
	* quadmath_io.c: Removed.
	* gdtoa/gdtoa.c: Removed.
	* gdtoa/g__fmt.c: Removed.
	* gdtoa/g_Qfmt.c: Removed.
	* gdtoa/dmisc.c: Removed.
	* gdtoa/ulp.c: Removed.
	* config.h.in: Regenerated.
	* configure: Regenerated.
	* Makefile.in: Regenerated.

	* io/write_float.def (DTOAQ): Use quadmath_snprintf instead of
	quadmath_flt128tostr.
	* io/transfer128.c (tmp2): Initialize to quadmath_snprintf instead
	of quadmath_flt128tostr.

From-SVN: r170135
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	PR fortran/47642
	* libquadmath.texi (quadmath_snprintf): Document.
	(quadmath_flt128tostr): Remove.
	* Makefile.am (libquadmath_la_SOURCES): Add printf/*.c.
	Remove  quadmath_io.c, gdtoa/gdtoa.c, gdtoa/g__fmt.c,
	gdtoa/g_Qfmt.c, gdtoa/dmisc.c and gdtoa/ulp.c.
	* quadmath.h (quadmath_snprintf): New prototype.
	(quadmath_flt128tostr): Remove.
	* quadmath_weak.h (quadmath_snprintf): Add.
	(quadmath_flt128tostr): Remove.
	* configure.ac: New AC_CHECK_HEADERS headers: langinfo.h, wchar.h,
	wctype.h, limits.h, ctype.h, printf.h, errno.h.
	(AC_USE_SYSTEM_EXTENSIONS): Add.
	(HAVE_HIDDEN_VISIBILITY, HAVE_PRINTF_HOOKS,
	USE_LOCALE_SUPPORT, USE_I18N_NUMBER_H): New checks.
	* quadmath.map (QUADMATH_1.0): Add quadmath_snprintf.  Remove
	quadmath_flt128tostr.
	* printf/printf_fphex.c: New file.
	* printf/_itowa.h: New file.
	* printf/mul_n.c: New file.
	* printf/quadmath-printf.h: New file.
	* printf/submul_1.c: New file.
	* printf/quadmath-printf.c: New file.
	* printf/gmp-impl.h: New file.
	* printf/lshift.c: New file.
	* printf/fpioconst.h: New file.
	* printf/add_n.c: New file.
	* printf/cmp.c: New file.
	* printf/sub_n.c: New file.
	* printf/mul.c: New file.
	* printf/divrem.c: New file.
	* printf/addmul_1.c: New file.
	* printf/printf_fp.c: New file.
	* printf/_itoa.h: New file.
	* printf/fpioconst.c: New file.
	* printf/_i18n_number.h: New file.
	* printf/flt1282mpn.c: New file.
	* printf/rshift.c: New file.
	* printf/mul_1.c: New file.
	* quadmath_io.c: Removed.
	* gdtoa/gdtoa.c: Removed.
	* gdtoa/g__fmt.c: Removed.
	* gdtoa/g_Qfmt.c: Removed.
	* gdtoa/dmisc.c: Removed.
	* gdtoa/ulp.c: Removed.
	* config.h.in: Regenerated.
	* configure: Regenerated.
	* Makefile.in: Regenerated.

	* io/write_float.def (DTOAQ): Use quadmath_snprintf instead of
	quadmath_flt128tostr.
	* io/transfer128.c (tmp2): Initialize to quadmath_snprintf instead
	of quadmath_flt128tostr.

From-SVN: r170135
</pre>
</div>
</content>
</entry>
</feed>
