Bruno Haible | 1 Apr 2012 19:39

log10: more tests and workarounds

Continuing the math function support, I'm adding more tests and fixes
to the 'log10', 'log10f', 'log10l' modules.

Bugs worked around:
  - On OSF/1 5.1, log10(-0.0) is NaN, should be -Infinity.
    Likewise for log10f and log10l.
  - Wrong result for negative arguments on NetBSD 5.1 and Solaris.
  - On AIX 5.1, the undeclared log10l function produces broken results.
  - On IRIX 6.5, the system function produces -Infinity and +Infinity value
    variants that print like the real -Infinity and +Infinity, but does not
    compare == to the real -Infinity or +Infinity.

2012-04-01  Bruno Haible  <bruno <at> clisp.org>

	log10l: Work around log10l-ieee test failure on IRIX 6.5.
	* lib/log10l.c: Include <float.h>
	(log10l): On IRIX, normalize the +Infinity value.
	* modules/log10l (Depends-on): Add 'float'.
	* doc/posix-functions/log10l.texi: Mention the IRIX problem with
	+Infinity.

	log10f-ieee: Work around test failure on NetBSD 5.1.
	* m4/log10f-ieee.m4: New file.
	* m4/log10f.m4 (gl_FUNC_LOG10F): If gl_FUNC_LOG10F_IEEE is present,
	test whether log10f works with a negative argument. Replace it if not.
	* lib/log10f.c (log10f): For negative arguments, return NaN.
	* modules/log10f-ieee (Files): Add m4/log10f-ieee.m4.
	(configure.ac): Invoke gl_FUNC_LOG10F_IEEE.
	* doc/posix-functions/log10f.texi: Mention the log10f-ieee module.

(Continue reading)

Bruno Haible | 1 Apr 2012 22:01

Re: unistring bug

Hi Andy,

Andy Wingo wrote in
<https://lists.gnu.org/archive/html/bug-gnulib/2012-04/msg00000.html>:
> The following program causes a segfault in the unistring that is current
> in Debian sid:
> 
>     #include <unistr.h>
>     #include <stdio.h>
> 
>     int main (int argc, char *argv[])
>     {
>       int floral_leaf = 0x2767;
>       
>       printf ("floral leaf: %s\n", u32_to_u8 (&floral_leaf, 1, 0, 0));
> 
>       return 0;
>     }

This is normal documented behaviour. The function's description at [1]

   uint8_t * u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf, size_t *lengthp)

is preceded by the general conventions explanation [2]:

   Functions returning a string result take a (resultbuf, lengthp)
   argument pair. If resultbuf is not NULL and the result fits into
   *lengthp units, it is put in resultbuf, and resultbuf is returned.
   Otherwise, a freshly allocated string is returned. In both cases,
   *lengthp is set to the length (number of units) of the returned string.
(Continue reading)

Andy Wingo | 1 Apr 2012 23:07
Picon
Favicon

Re: unistring bug

On Sun 01 Apr 2012 13:01, Bruno Haible <bruno <at> clisp.org> writes:

> This is normal documented behaviour. The function's description at [1]
>
>    uint8_t * u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf, size_t *lengthp)
>
> is preceded by the general conventions explanation [2]:
>
>    Functions returning a string result take a (resultbuf, lengthp)
>    argument pair. If resultbuf is not NULL and the result fits into
>    *lengthp units, it is put in resultbuf, and resultbuf is returned.
>    Otherwise, a freshly allocated string is returned. In both cases,
>    *lengthp is set to the length (number of units) of the returned string.
>    In case of error, NULL is returned and errno is set.
>
> In your program, the "Otherwise" applies, so:
>    - A freshly allocated string is returned.
>    - *lengthp is set to the length (number of units) of the returned string.
>
> Since you pass lengthp == a null pointer, you provoke a null pointer
> dereference.

Thanks for the explanation.  I've fixed Guile's usage of this function
(introduced recently).

Regards,

Andy
--

-- 
http://wingolog.org/
(Continue reading)

Gilles Espinasse | 2 Apr 2012 20:20
Picon
Favicon

[PATCH v2] fix not a string literal warning in test_xasprintf

With gcc-4.4.5 patched with defaults-format-security.patch, coreutils emit
test-xvasprintf.c: In function 'test_xasprintf':
test-xvasprintf.c:98: warning: format not a string literal and no format arguments

There is a gnulib-tests/Makefile hack preventing the warning in case coreutils is
compiled with --enable-gcc-warnings but the hack is not triggered when gcc default
behavior is changed or -Wformat-security is in CFLAGS.

Remove the code hack preventing format-zero-length warning and replace by a
pragma GCC diagnostic ignored in top of code.
That way, there is no more string literal warning and gnulib-tests/Makefile hack
could be removed.

Signed-off-by: Gilles Espinasse <g.esp <at> free.fr>
---
 tests/test-xvasprintf.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/tests/test-xvasprintf.c b/tests/test-xvasprintf.c
index 4a90059..4c281f1 100644
--- a/tests/test-xvasprintf.c
+++ b/tests/test-xvasprintf.c
 <at>  <at>  -16,6 +16,9  <at>  <at> 

 /* Written by Bruno Haible <bruno <at> clisp.org>, 2007.  */

+ /* Silence gcc warning  */
+#pragma GCC diagnostic ignored "-Wformat-zero-length"
+
 #include <config.h>
(Continue reading)

Picon

[PATCH] Use opaque struct rather than char * in regex.h

Hello, all. It's a common problem when program attempts to access
unaligned pointer. On x86 this usually goes unnoticed but on other CPUs
it results in segmentation fault. -Wcast-align is a good way to check
that no such problem occurs. Unfortunately regex module breaks the
invariants by casting char * to a re_dfa_t *. Attached patch fixes it

--

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

Attachment (align.diff): text/x-diff, 1340 bytes
Picon

[PATCH, resend] Handle multibyte codepoint width properly

I'm not sure if previous time I sent with or without \0 bugfix. Resending

--

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

Attachment (fmtstream.diff): text/x-diff, 5067 bytes
Bruno Haible | 3 Apr 2012 14:09

workarounds for logb, new modules 'logbf', 'logbl'

The next math function to be supported by gnulib is logb(), with its
variants logbf(), logbl().

Notable bugs fixed: glibc, Solaris, and Cygwin 1.5.x return a wrong result
when the argument is a denormalized number.

2012-04-03  Bruno Haible  <bruno <at> clisp.org>

	Tests for module 'logbl-ieee'.
	* modules/logbl-ieee-tests: New file.
	* tests/test-logbl-ieee.c: New file.

	New module 'logbl-ieee'.
	* modules/logbl-ieee: New file.

	Tests for module 'logb-ieee'.
	* modules/logb-ieee-tests: New file.
	* tests/test-logb-ieee.c: New file.

	New module 'logb-ieee'.
	* modules/logb-ieee: New file.

	Tests for module 'logbf-ieee'.
	* modules/logbf-ieee-tests: New file.
	* tests/test-logbf-ieee.c: New file.
	* tests/test-logb-ieee.h: New file.

	New module 'logbf-ieee'.
	* modules/logbf-ieee: New file.

(Continue reading)

Bruno Haible | 3 Apr 2012 22:04

new modules 'ilogb', 'ilogbf', 'ilogbl'

ilogb() is a variant of logb(). Nearly the same replacement code as for
logb().

Notable bugs fixed: The value for zero, infinite, or NaN arguments is
broken on NetBSD, OpenBSD, and old AIX 5.1.

2012-04-03  Bruno Haible  <bruno <at> clisp.org>

	Tests for module 'ilogbl'.
	* modules/ilogbl-tests: New file.
	* tests/test-ilogbl.c: New file.

	New module 'ilogbl'.
	* lib/math.in.h (ilogbl): New declaration.
	* lib/ilogbl.c: New file.
	* m4/ilogbl.m4: New file.
	* m4/math_h.m4 (gl_MATH_H): Test whether ilogbl is declared.
	(gl_MATH_H_DEFAULTS): Initialize GNULIB_ILOGBL, HAVE_ILOGBL.
	* modules/math (Makefile.am): Substitute GNULIB_ILOGBL, HAVE_ILOGBL.
	Split sed invocation, to avoid the limit of 100 substitutions of
	HP-UX 'sed'.
	* modules/ilogbl: New file.
	* tests/test-math-c++.cc: Check the declaration of ilogbl.
	* doc/posix-functions/ilogbl.texi: Mention the new module.

2012-04-03  Bruno Haible  <bruno <at> clisp.org>

	Tests for module 'ilogbf'.
	* modules/ilogbf-tests: New file.
	* tests/test-ilogbf.c: New file.
(Continue reading)

Jim Meyering | 4 Apr 2012 06:34
Gravatar

Re: [PATCH] Use opaque struct rather than char * in regex.h

Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Hello, all. It's a common problem when program attempts to access
> unaligned pointer. On x86 this usually goes unnoticed but on other CPUs
> it results in segmentation fault. -Wcast-align is a good way to check
> that no such problem occurs. Unfortunately regex module breaks the
> invariants by casting char * to a re_dfa_t *. Attached patch fixes it

Hi Vlad,

How about just adding a #pragma to disable that warning, instead,
assuming it was just in regcomp.c?

The alternative (your patch or similar) would move the definition
of re_dfa_t from its private header to a public one.  If, say, the
glibc folks prefer your patch, you'll want to adjust this comment
to match the new code:

   /* Space that holds the compiled pattern.  It is declared as
      'unsigned char *' because its elements are sometimes used as
      array indexes.  */
-  unsigned char *__REPB_PREFIX(buffer);
+  re_dfa_t *__REPB_PREFIX(buffer);

Paul Eggert | 4 Apr 2012 10:03
Favicon

Re: [PATCH] Use opaque struct rather than char * in regex.h

On 04/03/2012 09:34 PM, Jim Meyering wrote:
> The alternative (your patch or similar) would move the definition
> of re_dfa_t from its private header to a public one.

We needn't expose the typedef, just the struct tag for an incomplete
type; this doesn't reveal anything other than the struct tag, and the
tag begins with re_ so it is in the POSIX reserved space and POSIX
would allow this change.

Also, changing the type makes the code more honest.  The code
never uses the value according to its declared type 'unsigned char *',
so that type is bogus.  I expect it's there only for portability to
pre-C89 compilers, which is no longer an issue with either gnulib or with
glibc.  So whenever we merge gnulib's changes into glibc, we might
as well merge this in too.

However, the patch kept a number of unnecessary casts.  I installed
the following instead.  And thanks for the bug report!

regex: remove unnecessary type punning
Problem reported by Vladimir Serbinenko in
<http://lists.gnu.org/archive/html/bug-gnulib/2012-04/msg00006.html>.
* lib/regex.h (struct re_pattern_buffer): Change the type of
__REPB_PREFIX(buffer) from unsigned char * to struct re_dfa_t *.
Fix comment to match code.
* lib/regcomp.c (re_compile_fastmap, re_compile_fastmap_iter, regfree)
(re_compile_internal, free_workarea_compile, analyze, lower_subexp)
(parse, parse_reg_exp, parse_branch, parse_expression, parse_sub_exp):
* lib/regexec.c (regexec, re_search_stub, re_search_internal)
(set_regs):
(Continue reading)


Gmane