Skip site navigation (1) Skip section navigation (2)

fix a bogus line in dynahash.c

From: "Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu>
To: pgsql-patches(at)postgresql(dot)org
Subject: fix a bogus line in dynahash.c
Date: 2005-05-25 02:14:16
Message-ID: d70n5f$1ii9$1@news.hub.org (view raw or flat)
Thread:
Lists: pgsql-patches
Change elog(ERROR) to Assert(false) for two reasons:

(1) "unrecognized hash action code" could hardly really happen;
(2) even if it could happen, elog(ERROR) won't save us since in many places
we have to check the return code of hash_search() and decide the error
level.


On a separate matter, can anyone please explain me how this piece of code
works:

    /* no free elements.  allocate another chunk of buckets */
    if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR))
     return NULL; /* out of memory */

element_alloc() in fact uses MemoryContextAlloc() stuff. So if
element_alloc() fails, it actually elog(ERROR) itself and jump out of our
control, and we could never get a chance to check its returned value. So
many places like this:

if (!hash_search(... HASH_ENTER ...))
    elog( ...)

could never happen?


Regards,
Qingqing


Index: dynahash.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v
retrieving revision 1.60
diff -c -r1.60 dynahash.c
*** dynahash.c  16 May 2005 00:19:04 -0000      1.60
--- dynahash.c  25 May 2005 01:57:42 -0000
***************
*** 680,687 ****
                        return (void *) ELEMENTKEY(currBucket);
        }

!       elog(ERROR, "unrecognized hash action code: %d", (int) action);
!
        return NULL;                            /* keep compiler quiet */
  }

--- 680,688 ----
                        return (void *) ELEMENTKEY(currBucket);
        }

!       /* Should never be here */
!       Assert(false);
!
        return NULL;                            /* keep compiler quiet */
  }



Responses

pgsql-patches by date

Next:From: Tom LaneDate: 2005-05-25 02:44:13
Subject: Re: [PATCH] pg_autovacuum commandline password hiding.
Previous:From: Neil ConwayDate: 2005-05-25 01:46:43
Subject: Re: [PATCH] pg_autovacuum commandline password hiding.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group