Skip to content

Commit

Permalink
PG-1101 Fix some linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Oct 11, 2024
1 parent 9fdd429 commit c013c8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ init_guc(void)

/* Maximum value must be greater or equal to minimum + 1.0 */
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
Expand All @@ -303,7 +304,8 @@ check_histogram_min(double *newval, void **extra, GucSource source)
}

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));
}
Expand Down
24 changes: 13 additions & 11 deletions pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ static uint64 get_next_wbucket(pgsmSharedState *pgsm);

/*
* Module load callback
*
*/
/* cppcheck-suppress unusedFunction */
void
_PG_init(void)
_PG_init(void) /* cppcheck-suppress unusedFunction */
{
int rc;

Expand Down Expand Up @@ -1369,14 +1369,12 @@ pg_get_backend_status(void)
static int
pg_get_application_name(char *name, int buff_size)
{
PgBackendStatus *beentry;

/* Try to read application name from GUC directly */
if (application_name && *application_name)
snprintf(name, buff_size, "%s", application_name);
else
{
beentry = pg_get_backend_status();
PgBackendStatus *beentry = pg_get_backend_status();

Check warning on line 1377 in pg_stat_monitor.c

View check run for this annotation

Codecov / codecov/patch

pg_stat_monitor.c#L1377

Added line #L1377 was not covered by tests

if (!beentry)
snprintf(name, buff_size, "%s", "unknown");
Expand Down Expand Up @@ -1555,7 +1553,6 @@ pgsm_update_entry(pgsmEntry *entry,
/* If we have a parent query, store it in the raw dsa area */
if (parent_query_len > 0)
{
char *qry_buff;
dsa_area *query_dsa_area = get_dsa_area_for_query_text();

/*
Expand All @@ -1567,7 +1564,8 @@ pgsm_update_entry(pgsmEntry *entry,

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);
qry_buff[parent_query_len] = 0;
/* store the dsa pointer for parent query text */
Expand Down Expand Up @@ -1696,12 +1694,14 @@ pgsm_store_error(const char *query, ErrorData *edata)
{
pgsmEntry *entry;
uint64 queryid = 0;
int len = strlen(query);
int len;

if (!query || len == 0)
if (query == NULL)
return;

len = strlen(query);
if (len == 0)
return;

queryid = pgsm_hash_string(query, len);

Expand Down Expand Up @@ -3959,7 +3959,6 @@ get_histogram_timings(PG_FUNCTION_ARGS)
static void
extract_query_comments(const char *query, char *comments, size_t max_len)
{
int rc;
size_t nmatch = 1;
regmatch_t pmatch;
regoff_t comment_len,
Expand All @@ -3968,7 +3967,8 @@ extract_query_comments(const char *query, char *comments, size_t 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)
break;

Expand Down Expand Up @@ -4002,6 +4002,7 @@ extract_query_comments(const char *query, char *comments, size_t max_len)
static uint64
get_query_id(JumbleState *jstate, Query *query)
{
/* cppcheck-suppress-begin nullPointerRedundantCheck symbolName=jstate */
uint64 queryid;

/* Set up workspace for query jumbling */
Expand All @@ -4016,5 +4017,6 @@ get_query_id(JumbleState *jstate, Query *query)
JumbleQuery(jstate, query);
queryid = pgsm_hash_string((const char *) jstate->jumble, jstate->jumble_len);
return queryid;
/* cppcheck-suppress-end nullPointerRedundantCheck symbolName=jstate */
}
#endif

0 comments on commit c013c8b

Please sign in to comment.