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
diff --git a/lib/regcomp.c b/lib/regcomp.c
index 311f2d5..0ddff4c 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -778,7 +778,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
if (dfa == NULL)
return REG_ESPACE;
preg->allocated = sizeof (re_dfa_t);
- preg->buffer = (unsigned char *) dfa;
+ preg->buffer = dfa;
}
preg->used = sizeof (re_dfa_t);
diff --git a/lib/regex.h b/lib/regex.h
index c1cd613..5317017 100644
--- a/lib/regex.h
+++ b/lib/regex.h
@@ -419,12 +419,15 @@ typedef enum
# define __REPB_PREFIX(name) __##name
#endif
+struct re_dfa_t;
+typedef struct re_dfa_t re_dfa_t;
+
struct re_pattern_buffer
{
/* 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);
/* Number of bytes to which 'buffer' points. */
__re_long_size_t __REPB_PREFIX(allocated);
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 2b9f697..b91c5c5 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -410,8 +410,6 @@ struct re_string_t
typedef struct re_string_t re_string_t;
-struct re_dfa_t;
-typedef struct re_dfa_t re_dfa_t;
#ifndef _LIBC
# define internal_function
signature.asc
Description: OpenPGP digital signature
