[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-ed] [patch] ap_resize_buffer segfaults in special cases
From: |
Antonio Diaz Diaz |
Subject: |
Re: [Bug-ed] [patch] ap_resize_buffer segfaults in special cases |
Date: |
Tue, 14 Apr 2009 12:02:37 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.11) Gecko/20050905 |
poly-p man wrote:
On at least alpha, and sometimes sparc, -O3 (specifically the -finline-
functions flag) would cause a segfault in the testsuites and uses
elsewhere - anything that piped output to it.
Here is the "more radical" promised stuff. I have used an intermediate
void pointer to remove all casts from the calls to ap_resize_buffer.
Please, check this patch and tell me if it works so that I can apply the
same approach to "resize_buffer" and release a test version of ed.
Regards,
Antonio.
diff -urdN ../old_src/carg_parser.c ./carg_parser.c
--- ../old_src/carg_parser.c 2009-01-15 12:24:29.000000000 +0100
+++ ./carg_parser.c 2009-04-14 11:27:38.000000000 +0200
@@ -22,13 +22,13 @@
/* assure at least a minimum size for buffer `buf' */
-char ap_resize_buffer( void *buf, const int min_size )
+char ap_resize_buffer( void **buf, const int min_size )
{
void *new_buf = 0;
- if( *(void **)buf ) new_buf = realloc( *(void **)buf, min_size );
+ if( *buf ) new_buf = realloc( *buf, min_size );
else new_buf = malloc( min_size );
if( !new_buf ) return 0;
- *(void **)buf = new_buf;
+ *buf = new_buf;
return 1;
}
@@ -37,13 +37,16 @@
{
const int len = strlen( argument );
ap_Record *p;
- if( !ap_resize_buffer( (void *)&(ap->data),
- ( ap->data_size + 1 ) * sizeof( ap_Record ) ) )
+ void * alias = ap->data;
+ if( !ap_resize_buffer( &alias, ( ap->data_size + 1 ) * sizeof( ap_Record ) )
)
return 0;
+ ap->data = (ap_Record *)alias;
p = &(ap->data[ap->data_size]);
p->code = code;
p->argument = 0;
- if( !ap_resize_buffer( (void *)&(p->argument), len + 1 ) ) return 0;
+ alias = p->argument;
+ if( !ap_resize_buffer( &alias, len + 1 ) ) return 0;
+ p->argument = (char *)alias;
strncpy( p->argument, argument, len + 1 );
++ap->data_size;
return 1;
@@ -53,8 +56,9 @@
char add_error( Arg_parser * ap, const char * msg )
{
const int len = strlen( msg );
- if( !ap_resize_buffer( (void *)&(ap->error), ap->error_size + len + 1 ) )
- return 0;
+ void * alias = ap->error;
+ if( !ap_resize_buffer( &alias, ap->error_size + len + 1 ) ) return 0;
+ ap->error = (char *)alias;
strncpy( ap->error + ap->error_size, msg, len + 1 );
ap->error_size += len;
return 1;
@@ -225,9 +229,11 @@
{
if( !in_order )
{
- if( !ap_resize_buffer( (void *)&non_options,
+ void * alias = non_options;
+ if( !ap_resize_buffer( &alias,
( non_options_size + 1 ) * sizeof( *non_options ) ) )
return 0;
+ non_options = (const char **)alias;
non_options[non_options_size++] = argv[argind++];
}
else if( !push_back_record( ap, 0, argv[argind++] ) ) return 0;