Fix libiberty/regex on 64-bit hosts (PR other/56245)

Submitted by Jakub Jelinek on Feb. 9, 2013, 8:24 a.m.

Details

Message ID 20130209082446.GT4385@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 9, 2013, 8:24 a.m.
Hi!

gengtype when built with -fsanitize=address fails on x86_64-linux.
The problem is that realloc often returns addresses which are more than 2GB
appart from the old value, and regex.c was using int variable for the
pointer difference to adjust the pointers in the realloced buffer.

glibc uses a different regex implementation for many years, so this isn't
something that should be first fixed in glibc.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-02-09  Jakub Jelinek  <jakub@redhat.com>

	PR other/56245
	* regex.c (PTR_INT_TYPE): Define.
	(EXTEND_BUFFER): Change incr type from int to PTR_INT_TYPE.


	Jakub

Comments

Ian Taylor Feb. 9, 2013, 6:19 p.m.
On Sat, Feb 9, 2013 at 12:24 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>
> 2013-02-09  Jakub Jelinek  <jakub@redhat.com>
>
>         PR other/56245
>         * regex.c (PTR_INT_TYPE): Define.
>         (EXTEND_BUFFER): Change incr type from int to PTR_INT_TYPE.

This is OK.

Thanks.

Ian

Patch hide | download patch | download mbox

--- libiberty/regex.c.jj	2011-05-02 18:39:35.000000000 +0200
+++ libiberty/regex.c	2013-02-08 18:33:18.136802070 +0100
@@ -46,9 +46,11 @@ 
 
 # if defined STDC_HEADERS && !defined emacs
 #  include <stddef.h>
+#  define PTR_INT_TYPE ptrdiff_t
 # else
 /* We need this for `regex.h', and perhaps for the Emacs include files.  */
 #  include <sys/types.h>
+#  define PTR_INT_TYPE long
 # endif
 
 # define WIDE_CHAR_SUPPORT (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC)
@@ -2045,7 +2047,7 @@  static reg_errcode_t byte_compile_range
     /* How many characters the new buffer can have?  */			\
     wchar_count = bufp->allocated / sizeof(UCHAR_T);			\
     if (wchar_count == 0) wchar_count = 1;				\
-    /* Truncate the buffer to CHAR_T align.  */			\
+    /* Truncate the buffer to CHAR_T align.  */				\
     bufp->allocated = wchar_count * sizeof(UCHAR_T);			\
     RETALLOC (COMPILED_BUFFER_VAR, wchar_count, UCHAR_T);		\
     bufp->buffer = (char*)COMPILED_BUFFER_VAR;				\
@@ -2054,7 +2056,7 @@  static reg_errcode_t byte_compile_range
     /* If the buffer moved, move all the pointers into it.  */		\
     if (old_buffer != COMPILED_BUFFER_VAR)				\
       {									\
-	int incr = COMPILED_BUFFER_VAR - old_buffer;			\
+	PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer;		\
 	MOVE_BUFFER_POINTER (b);					\
 	MOVE_BUFFER_POINTER (begalt);					\
 	if (fixup_alt_jump)						\
@@ -2082,7 +2084,7 @@  static reg_errcode_t byte_compile_range
     /* If the buffer moved, move all the pointers into it.  */		\
     if (old_buffer != COMPILED_BUFFER_VAR)				\
       {									\
-	int incr = COMPILED_BUFFER_VAR - old_buffer;			\
+	PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer;		\
 	MOVE_BUFFER_POINTER (b);					\
 	MOVE_BUFFER_POINTER (begalt);					\
 	if (fixup_alt_jump)						\