From: Tom Lane Date: Thu, 12 Mar 2009 00:53:48 +0000 (+0000) Subject: Fix core dump due to null-pointer dereference in to_char() when datetime X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=b06d421e6caa7a49e11bb27f77ff63cba33ef5dd;p=users%2Fbernd%2Fpostgres.git Fix core dump due to null-pointer dereference in to_char() when datetime format codes are misapplied to a numeric argument. (The code still produces a pretty bogus error message in such cases, but I'll settle for stopping the crash for now.) Per bug #4700 from Sergey Burladyan. Problem exists in all supported branches, so patch all the way back. In HEAD, also clean up some ugly coding in the nearby cache management code. --- diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index 6d69ce1b98..f82fd2b25b 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -347,7 +347,7 @@ static int DCHCounter = 0; /* global cache for --- number part */ static NUMCacheEntry NUMCache[NUM_CACHE_FIELDS + 1]; -static NUMCacheEntry *last_NUMCacheEntry; +static NUMCacheEntry *last_NUMCacheEntry = NUMCache + 0; static int n_NUMCache = 0; /* number of entries */ static int NUMCounter = 0;