PG-1101 Fix some linter warnings

PG-1101-cppcheck
Artem Gavrilov 2024-10-11 19:13:11 +02:00
parent 9fdd429353
commit c013c8b1ed
2 changed files with 17 additions and 13 deletions

6
guc.c
View File

@ -293,7 +293,8 @@ init_guc(void)
/* Maximum value must be greater or equal to minimum + 1.0 */ /* Maximum value must be greater or equal to minimum + 1.0 */
static bool static bool
check_histogram_min(double *newval, void **extra, GucSource source) check_histogram_min(double *newval, void **extra, GucSource source) /* cppcheck-suppress
* constParameterCallback */
{ {
/* /*
* During module initialization PGSM_HISTOGRAM_MIN is initialized before * During module initialization PGSM_HISTOGRAM_MIN is initialized before
@ -303,7 +304,8 @@ check_histogram_min(double *newval, void **extra, GucSource source)
} }
static bool static bool
check_histogram_max(double *newval, void **extra, GucSource source) check_histogram_max(double *newval, void **extra, GucSource source) /* cppcheck-suppress
* constParameterCallback */
{ {
return (*newval >= (pgsm_histogram_min + 1.0)); return (*newval >= (pgsm_histogram_min + 1.0));
} }

View File

@ -263,10 +263,10 @@ static uint64 get_next_wbucket(pgsmSharedState *pgsm);
/* /*
* Module load callback * Module load callback
*
*/ */
/* cppcheck-suppress unusedFunction */
void void
_PG_init(void) _PG_init(void) /* cppcheck-suppress unusedFunction */
{ {
int rc; int rc;
@ -1369,14 +1369,12 @@ pg_get_backend_status(void)
static int static int
pg_get_application_name(char *name, int buff_size) pg_get_application_name(char *name, int buff_size)
{ {
PgBackendStatus *beentry;
/* Try to read application name from GUC directly */ /* Try to read application name from GUC directly */
if (application_name && *application_name) if (application_name && *application_name)
snprintf(name, buff_size, "%s", application_name); snprintf(name, buff_size, "%s", application_name);
else else
{ {
beentry = pg_get_backend_status(); PgBackendStatus *beentry = pg_get_backend_status();
if (!beentry) if (!beentry)
snprintf(name, buff_size, "%s", "unknown"); snprintf(name, buff_size, "%s", "unknown");
@ -1555,7 +1553,6 @@ pgsm_update_entry(pgsmEntry *entry,
/* If we have a parent query, store it in the raw dsa area */ /* If we have a parent query, store it in the raw dsa area */
if (parent_query_len > 0) if (parent_query_len > 0)
{ {
char *qry_buff;
dsa_area *query_dsa_area = get_dsa_area_for_query_text(); dsa_area *query_dsa_area = get_dsa_area_for_query_text();
/* /*
@ -1567,7 +1564,8 @@ pgsm_update_entry(pgsmEntry *entry,
if (DsaPointerIsValid(qry)) if (DsaPointerIsValid(qry))
{ {
qry_buff = dsa_get_address(query_dsa_area, qry); char *qry_buff = dsa_get_address(query_dsa_area, qry);
memcpy(qry_buff, nested_query_txts[nesting_level - 1], parent_query_len); memcpy(qry_buff, nested_query_txts[nesting_level - 1], parent_query_len);
qry_buff[parent_query_len] = 0; qry_buff[parent_query_len] = 0;
/* store the dsa pointer for parent query text */ /* store the dsa pointer for parent query text */
@ -1696,12 +1694,14 @@ pgsm_store_error(const char *query, ErrorData *edata)
{ {
pgsmEntry *entry; pgsmEntry *entry;
uint64 queryid = 0; uint64 queryid = 0;
int len = strlen(query); int len;
if (!query || len == 0) if (query == NULL)
return; return;
len = strlen(query); len = strlen(query);
if (len == 0)
return;
queryid = pgsm_hash_string(query, len); queryid = pgsm_hash_string(query, len);
@ -3959,7 +3959,6 @@ get_histogram_timings(PG_FUNCTION_ARGS)
static void static void
extract_query_comments(const char *query, char *comments, size_t max_len) extract_query_comments(const char *query, char *comments, size_t max_len)
{ {
int rc;
size_t nmatch = 1; size_t nmatch = 1;
regmatch_t pmatch; regmatch_t pmatch;
regoff_t comment_len, regoff_t comment_len,
@ -3968,7 +3967,8 @@ extract_query_comments(const char *query, char *comments, size_t max_len)
while (total_len < max_len) while (total_len < max_len)
{ {
rc = regexec(&preg_query_comments, s, nmatch, &pmatch, 0); int rc = regexec(&preg_query_comments, s, nmatch, &pmatch, 0);
if (rc != 0) if (rc != 0)
break; break;
@ -4002,6 +4002,7 @@ extract_query_comments(const char *query, char *comments, size_t max_len)
static uint64 static uint64
get_query_id(JumbleState *jstate, Query *query) get_query_id(JumbleState *jstate, Query *query)
{ {
/* cppcheck-suppress-begin nullPointerRedundantCheck symbolName=jstate */
uint64 queryid; uint64 queryid;
/* Set up workspace for query jumbling */ /* Set up workspace for query jumbling */
@ -4016,5 +4017,6 @@ get_query_id(JumbleState *jstate, Query *query)
JumbleQuery(jstate, query); JumbleQuery(jstate, query);
queryid = pgsm_hash_string((const char *) jstate->jumble, jstate->jumble_len); queryid = pgsm_hash_string((const char *) jstate->jumble, jstate->jumble_len);
return queryid; return queryid;
/* cppcheck-suppress-end nullPointerRedundantCheck symbolName=jstate */
} }
#endif #endif