httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roy T. Fielding" <field...@kiwi.ICS.UCI.EDU>
Subject Re: memory management goof in alloc.c (fwd)
Date Fri, 07 Mar 1997 18:29:27 GMT
>    if (arr->nelts == arr->nalloc) {
>!     int new_size = arr->nalloc * 2;
>!     char *new_data;
>!     
>!     if (new_size == 0) ++new_size;
>! 
>!     new_data = pcalloc (arr->pool, arr->elt_size * new_size);

In principle the patch is good, but I don't like the way it
sets new_size and then increments it.  That bit of uglyness was
inherited from the other function, but I'd prefer to fix both
as in the following patch.

.....Roy

Index: alloc.c
===================================================================
RCS file: /export/home/cvs/apache/src/alloc.c,v
retrieving revision 1.22
diff -c -r1.22 alloc.c
*** alloc.c	1997/01/19 17:43:27	1.22
--- alloc.c	1997/03/07 18:25:38
***************
*** 461,471 ****
  void *push_array (array_header *arr)
  {
    if (arr->nelts == arr->nalloc) {
!     char *new_data = pcalloc (arr->pool, arr->nalloc * arr->elt_size * 2);
  
      memcpy (new_data, arr->elts, arr->nalloc * arr->elt_size);
      arr->elts = new_data;
!     arr->nalloc *= 2;
    }
  
    ++arr->nelts;
--- 461,474 ----
  void *push_array (array_header *arr)
  {
    if (arr->nelts == arr->nalloc) {
!     int new_size = (arr->nalloc <= 0) ? 1 : arr->nalloc * 2;
!     char *new_data;
!     
!     new_data = pcalloc (arr->pool, arr->elt_size * new_size);
  
      memcpy (new_data, arr->elts, arr->nalloc * arr->elt_size);
      arr->elts = new_data;
!     arr->nalloc = new_size;
    }
  
    ++arr->nelts;
***************
*** 477,487 ****
    int elt_size = dst->elt_size;
    
    if (dst->nelts + src->nelts > dst->nalloc) {
!     int new_size = dst->nalloc * 2;
      char *new_data;
  
-     if (new_size == 0) ++new_size;
-     
      while (dst->nelts + src->nelts > new_size)
        new_size *= 2;
  
--- 480,488 ----
    int elt_size = dst->elt_size;
    
    if (dst->nelts + src->nelts > dst->nalloc) {
!     int new_size = (dst->nalloc <= 0) ? 1 : dst->nalloc * 2;
      char *new_data;
  
      while (dst->nelts + src->nelts > new_size)
        new_size *= 2;
  

Mime
View raw message