Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coverity warning about potential overflow #4669

Merged
merged 2 commits into from Sep 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bgw/job_stat.c
Expand Up @@ -203,9 +203,9 @@ calculate_next_start_on_failure(TimestampTz finish_time, int consecutive_failure
float8 multiplier = (consecutive_failures > MAX_FAILURES_MULTIPLIER ? MAX_FAILURES_MULTIPLIER :
consecutive_failures);
MemoryContext oldctx;
Assert(consecutive_failures > 0);
int64 max_slots =
(1 << consecutive_failures) - 1; /* 2^(consecutive_failures) - 1, at most 2^20 */
Assert(consecutive_failures > 0 && multiplier < 63);
/* 2^(consecutive_failures) - 1, at most 2^20 */
int64 max_slots = (INT64CONST(1) << (int64) multiplier) - INT64CONST(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of (int64)(float8)(int) but approving.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, why are we using floats there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the call

ival = DirectFunctionCall2(interval_mul, IntervalPGetDatum(&job->fd.retry_period), Float8GetDatum(multiplier));

on line 237

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah!

int64 rand_backoff = random() % (max_slots * USECS_PER_SEC);

if (!IS_VALID_TIMESTAMP(finish_time))
Expand Down