This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fix obscure obstack bug


Ulrich / DJ,

If you use a user-defined allocation function for obstacks, that
allocation function might, in addition to allocating the memory, want
to adjust the chunk_size so that, for example, future allocations use
larger chunks.  I tried to do something like this in CPP, but it fail
with a segfault, because of a bug in obstack.c.

The patch below is against the libiberty obstack.c in GCC, but applies
cleanly to Glibc as well.  The two lines changing the argument passed
to CALL_CHUNKFUN are for clarity only, in view of the subsequent
change, which is necessary for correctness in the circumstances I
describe above.

Please apply if you agree.

Neil.

	* obstack.c (_obstack_begin, _obstack_begin_1): Set the chunk
	limit based on the requested allocation size, not chunk_size,
	which might be changed by a user-defined allocator.

Index: obstack.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/obstack.c,v
retrieving revision 1.4
diff -u -p -r1.4 obstack.c
--- obstack.c	2000/12/29 19:37:03	1.4
+++ obstack.c	2001/09/15 17:05:13
@@ -192,12 +192,12 @@ _obstack_begin (h, size, alignment, chun
   h->alignment_mask = alignment - 1;
   h->use_extra_arg = 0;
 
-  chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+  chunk = h->chunk = CALL_CHUNKFUN (h, size);
   if (!chunk)
     (*obstack_alloc_failed_handler) ();
   h->next_free = h->object_base = chunk->contents;
   h->chunk_limit = chunk->limit
-    = (char *) chunk + h->chunk_size;
+    = (char *) chunk + size;
   chunk->prev = 0;
   /* The initial chunk now contains no empty object.  */
   h->maybe_empty_object = 0;
@@ -252,12 +252,12 @@ _obstack_begin_1 (h, size, alignment, ch
   h->extra_arg = arg;
   h->use_extra_arg = 1;
 
-  chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+  chunk = h->chunk = CALL_CHUNKFUN (h, size);
   if (!chunk)
     (*obstack_alloc_failed_handler) ();
   h->next_free = h->object_base = chunk->contents;
   h->chunk_limit = chunk->limit
-    = (char *) chunk + h->chunk_size;
+    = (char *) chunk + size;
   chunk->prev = 0;
   /* The initial chunk now contains no empty object.  */
   h->maybe_empty_object = 0;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]