bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stdbool.h with AIX C-compiler


From: Eric Blake
Subject: Re: stdbool.h with AIX C-compiler
Date: Thu, 15 May 2008 20:39:21 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Heinrich Mislik <Heinrich.Mislik <at> univie.ac.at> writes:

Hello Heinrich, and thanks for the report.

> here is a problem with stdbool.h from gnulib:
>     pbool(256);

Inherently non-portable when attempted with a C89 compiler.  And Gnulib's 
<stdbool.h> replacement documents it as one of the limitations of using the 
replacement <stdbool.h>:

|   Limitations of this substitute, when used in a C89 environment:
|
|       - <stdbool.h> must be #included before the '_Bool' type can be used.
|
|       - You cannot assume that _Bool is a typedef; it might be a macro.
|
|       - Bit-fields of type 'bool' are not supported.  Portable code
|         should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
|
|       - In C99, casts and automatic conversions to '_Bool' or 'bool' are
|         performed in such a way that every nonzero value gets converted
|         to 'true', and zero gets converted to 'false'.  This doesn't work
|         with this substitute.  With this substitute, only the values 0 and 1
|         give the expected result when converted to _Bool' or 'bool'.

> I came across this, when the -iregex option of find didn't work 
> (behaves like -regex). The above test-program reflects the situation 
> in line 778 of regcomp.c:
> 
>  err = re_string_construct (&regexp, pattern, length, preg-translate,
>                               syntax & RE_ICASE, dfa);

Therefore the bug is in regcomp.c, for violating the limits of <stdbool.h> 
usage.  The proper fix is not in the stdbool module (since there is no way to 
make C89 behave the way C99 requires bool to act), but in the regex module, to 
explicitly compare the result of & against 0 in order to create a true 0/1 
value regardless of what underlying type we are really using.

I'm committing this (hmm, we need to push this back into glibc; are there any 
other pending regex portability gotchas that need to be flowed to glibc?):


>From 39fc05fb065833938aad7ab0285f017e616a60f2 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 15 May 2008 14:37:29 -0600
Subject: [PATCH] Fix violation of <stdbool.h> replacement in regex.

* lib/regcomp.c (re_compile_internal): Avoid implicit cast to bool.
Reported by Heinrich Mislik <address@hidden>.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog     |    8 +++++++-
 lib/regcomp.c |    4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2e4d587..04ee46e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-05-15  Eric Blake  <address@hidden>
+
+       Fix violation of <stdbool.h> replacement in regex.
+       * lib/regcomp.c (re_compile_internal): Avoid implicit cast to bool.
+       Reported by Heinrich Mislik <address@hidden>.
+
 2008-05-15  Jim Meyering  <address@hidden>
 
        avoid distracting test output when git or cvs is not fount
diff --git a/lib/regcomp.c b/lib/regcomp.c
index dc15666..a3a745d 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -1,5 +1,5 @@
 /* Extended regular expression matching and search library.
-   Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
+   Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, 
Inc.
    This file is part of the GNU C Library.
    Contributed by Isamu Hasegawa <address@hidden>.
 
@@ -776,7 +776,7 @@ re_compile_internal (regex_t *preg, const char * pattern, 
size_t length,
   __libc_lock_init (dfa->lock);
 
   err = re_string_construct (&regexp, pattern, length, preg->translate,
-                            syntax & RE_ICASE, dfa);
+                            (syntax & RE_ICASE) != 0, dfa);
   if (BE (err != REG_NOERROR, 0))
     {
     re_compile_internal_free_return:
-- 
1.5.5.1







reply via email to

[Prev in Thread] Current Thread [Next in Thread]