From 920070f07ce96660d8360f0ecca25818776bb877 Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 19 Aug 2016 00:37:36 +1000 Subject: [PATCH] ckdb - add missing null checks in workinfo_age --- src/ckdb.c | 4 ++-- src/ckdb.h | 6 +++--- src/ckdb_data.c | 28 ++++++++++++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 712fe132..ccb994a6 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -117,7 +117,7 @@ static bool blistener_using_data; static bool breakdown_using_data; static bool replier_using_data; -/* Flag to notify thread changes +/* To notify thread changes * Set/checked under the function's main loop's first lock * This is always a 'delta' value meaning add or subtract that many */ int queue_threads_delta = 0; @@ -131,7 +131,7 @@ static int reload_breakdown_threads = -1; static int cmd_breakdown_threads = -1; // cpu count to breakdown thread ratio #define BREAKDOWN_RATIO 3 -// Flags to notify thread changes +// To notify thread changes int reload_breakdown_threads_delta = 0; int cmd_breakdown_threads_delta = 0; diff --git a/src/ckdb.h b/src/ckdb.h index a96f7d9f..8cec4bc3 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.403" +#define CKDB_VERSION DB_VERSION"-2.404" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -120,11 +120,11 @@ extern enum free_modes free_mode; // Define the array size for thread data #define THREAD_LIMIT 99 -/* Flag to notify thread changes +/* To notify thread changes * Set/checked under the function's main loop's first lock * This is always a 'delta' value meaning add or subtract that many */ extern int queue_threads_delta; -/* Flags to notify thread changes */ +// To notify thread changes extern int reload_breakdown_threads_delta; extern int cmd_breakdown_threads_delta; diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 20c6d88e..c5d79ce4 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -2288,9 +2288,11 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, ss_look.data = (void *)(&looksharesummary); K_RLOCK(sharesummary_free); ss_item = find_after_in_ktree(sharesummary_workinfoid_root, &ss_look, ss_ctx); - DATA_SHARESUMMARY_NULL(sharesummary, ss_item); - // complete could change, the id fields wont be changed/removed yet - STRNCPY(complete, sharesummary->complete); + if (ss_item) { + DATA_SHARESUMMARY(sharesummary, ss_item); + // complete could change, the id fields wont be changed/removed yet + STRNCPY(complete, sharesummary->complete); + } K_RUNLOCK(sharesummary_free); while (ss_item && sharesummary->workinfoid == workinfoid) { ss_tot++; @@ -2342,8 +2344,10 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, K_RLOCK(sharesummary_free); ss_item = next_in_ktree(ss_ctx); - DATA_SHARESUMMARY_NULL(sharesummary, ss_item); - STRNCPY(complete, sharesummary->complete); + if (ss_item) { + DATA_SHARESUMMARY(sharesummary, ss_item); + STRNCPY(complete, sharesummary->complete); + } K_RUNLOCK(sharesummary_free); } @@ -2375,9 +2379,11 @@ skip_ss: ks_look.data = (void *)(&lookkeysharesummary); K_RLOCK(keysharesummary_free); ks_item = find_after_in_ktree(keysharesummary_root, &ks_look, ks_ctx); - DATA_KEYSHARESUMMARY_NULL(keysharesummary, ks_item); - // complete could change, the id fields wont be changed/removed yet - STRNCPY(complete, keysharesummary->complete); + if (ks_item) { + DATA_KEYSHARESUMMARY(keysharesummary, ks_item); + // complete could change, the id fields wont be changed/removed yet + STRNCPY(complete, keysharesummary->complete); + } K_RUNLOCK(keysharesummary_free); while (ks_item && keysharesummary->workinfoid == workinfoid) { ks_tot++; @@ -2416,8 +2422,10 @@ skip_ss: K_RLOCK(keysharesummary_free); ks_item = next_in_ktree(ks_ctx); - DATA_KEYSHARESUMMARY_NULL(keysharesummary, ks_item); - STRNCPY(complete, keysharesummary->complete); + if (ks_item) { + DATA_KEYSHARESUMMARY(keysharesummary, ks_item); + STRNCPY(complete, keysharesummary->complete); + } K_RUNLOCK(keysharesummary_free); }