Fix covery warning.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 9 Aug 2023 02:10:28 +0000 (11:10 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 9 Aug 2023 02:19:11 +0000 (11:19 +0900)
Fix query cache module assigned time_t value to int32 variable. Change
the variable type to int64. Per Coverity.  Also use difftime() to
calculate time_t difference. This is a recommended practice.
https://www.jpcert.or.jp/sc-rules/c-msc05-c.html

src/include/query_cache/pool_memqcache.h
src/query_cache/pool_memqcache.c

index 9a94710eb305a6a8e560e7f8e832ed86bacfb390..0a4b41580bfd1429796b442bfa8fc4a74f21e630 100644 (file)
@@ -110,7 +110,7 @@ typedef struct
 {
        unsigned int total_length;      /* total length in bytes including myself */
        time_t          timestamp;              /* cache creation time */
-       int                     expire;                 /* cache expire duration in seconds */
+       int64           expire;                 /* cache expire duration in seconds */
 }                      POOL_CACHE_ITEM_HEADER;
 
 typedef struct
index 9d6080e7c4b26314a9aa753de2fa7531a237f54c..bee1aef39f5b363feba43a2c3444e3a166906b5e 100644 (file)
@@ -2730,7 +2730,7 @@ static POOL_CACHEID * pool_find_item_on_shmem_cache(POOL_QUERY_HASH * query_hash
        if (cih->expire > 0)
        {
                now = time(NULL);
-               if (now > (cih->timestamp + cih->expire))
+               if (difftime(now, cih->timestamp) > cih->expire)
                {
                        ereport(DEBUG1,
                                        (errmsg("memcache finding item"),