Skip to content

Commit

Permalink
Fix compilation warnings/errors and static analysis issues
Browse files Browse the repository at this point in the history
A deadcode issue is fixed by changing an AND to OR so that it is
actually possible to hit the condition. One change of palloc to
palloc0 to potentially prevent a Valgrind issue.
  • Loading branch information
RobAtticus committed Sep 10, 2018
1 parent a43cd04 commit f3ac7e0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/bgw/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ bgw_job_start(BgwJob *job)
static JobType
get_job_type_from_name(Name job_type_name)
{
for (int i = 0; i < _MAX_JOB_TYPE; i++)
int i;

for (i = 0; i < _MAX_JOB_TYPE; i++)
if (namestrcmp(job_type_name, job_type_names[i]) == 0)
return i;
return JOB_TYPE_UNKNOWN;
Expand Down
2 changes: 2 additions & 0 deletions src/bgw/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ assert_that_worker_has_stopped(ScheduledBgwJob *sjob)
static void
scheduled_bgw_job_transition_state_to(ScheduledBgwJob *sjob, JobState new_state)
{
#if USE_ASSERT_CHECKING
JobState prev_state = sjob->state;
#endif

BgwJobStat *job_stat;

Expand Down
2 changes: 1 addition & 1 deletion src/net/conn_plain.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plain_connect(Connection *conn, const char *host, const char *servname, int port
};
int ret;

if (NULL == servname && port <= 0 && port > MAX_PORT)
if (NULL == servname && (port <= 0 || port > MAX_PORT))
return -1;

/* Explicit port given. Use it instead of servname */
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ uuid_create(void)
* PG9.6 doesn't expose the internals of pg_uuid_t, so we just treat it as
* a byte array
*/
unsigned char *gen_uuid = palloc(UUID_LEN);
unsigned char *gen_uuid = palloc0(UUID_LEN);
bool rand_success = false;

#if PG10
Expand Down
4 changes: 3 additions & 1 deletion test/src/bgw/scheduler_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ test_job_3_long()
static TestJobType
get_test_job_type_from_name(Name job_type_name)
{
for (int i = 0; i < _MAX_TEST_JOB_TYPE; i++)
int i;

for (i = 0; i < _MAX_TEST_JOB_TYPE; i++)
{
if (namestrcmp(job_type_name, test_job_type_names[i]) == 0)
return i;
Expand Down

0 comments on commit f3ac7e0

Please sign in to comment.