diff options
author | Tom Lane | 2005-05-29 04:23:07 +0000 |
---|---|---|
committer | Tom Lane | 2005-05-29 04:23:07 +0000 |
commit | e92a88272eb2b164e7e8c625ad3f7ad267e0224f (patch) | |
tree | 3ca62f2a6cdd52f78911a50b628f16e77e70be78 /src/timezone/pgtz.c | |
parent | ecd70d75267ccf845e8f3976048d944e4ee35cf7 (diff) |
Modify hash_search() API to prevent future occurrences of the error
spotted by Qingqing Zhou. The HASH_ENTER action now automatically
fails with elog(ERROR) on out-of-memory --- which incidentally lets
us eliminate duplicate error checks in quite a bunch of places. If
you really need the old return-NULL-on-out-of-memory behavior, you
can ask for HASH_ENTER_NULL. But there is now an Assert in that path
checking that you aren't hoping to get that behavior in a palloc-based
hash table.
Along the way, remove the old HASH_FIND_SAVE/HASH_REMOVE_SAVED actions,
which were not being used anywhere anymore, and were surely too ugly
and unsafe to want to see revived again.
Diffstat (limited to 'src/timezone/pgtz.c')
-rw-r--r-- | src/timezone/pgtz.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/timezone/pgtz.c b/src/timezone/pgtz.c index bdf3d404079..38c71964065 100644 --- a/src/timezone/pgtz.c +++ b/src/timezone/pgtz.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.31 2005/05/23 21:54:02 momjian Exp $ + * $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.32 2005/05/29 04:23:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -971,6 +971,7 @@ identify_system_timezone(void) * load and parse the TZ definition file every time it is selected. */ static HTAB *timezone_cache = NULL; + static bool init_timezone_hashtable(void) { @@ -1013,14 +1014,18 @@ pg_tzset(const char *name) HASH_FIND, NULL); if (tzp) + { /* Timezone found in cache, nothing more to do */ return tzp; + } if (tzload(name, &tz.state) != 0) { if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0) + { /* Unknown timezone. Fail our call instead of loading GMT! */ return NULL; + } } strcpy(tz.TZname, name); @@ -1031,9 +1036,6 @@ pg_tzset(const char *name) HASH_ENTER, NULL); - if (!tzp) - return NULL; - strcpy(tzp->TZname, tz.TZname); memcpy(&tzp->state, &tz.state, sizeof(tz.state)); |