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:16:38 +0000 (11:16 +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 4622c96a0e78c7beed098f72bbc69815c836ed8f..9fc3e6a7abfebb1036065a80cfd3753df01d1adf 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 c1ae800d8fe4f5140f773f52fd8105be75666c2c..241763feb93c5f6ffe51ca8cf718f2edfa8c2472 100644 (file)
@@ -2732,7 +2732,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)
                {
                        /*
                         * We need to acquire an exclusive lock before removing the cache