-
Notifications
You must be signed in to change notification settings - Fork 82
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
Improve code according to the static analyzer report #821
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4243,7 +4243,7 @@ getExtensionList(void *ctx, PGresult *result) | |
} | ||
|
||
/* now loop over extension configuration, if any */ | ||
if (extension->config.count > 0) | ||
if (extension && extension->config.count > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really necessary as we early exit if extension is null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static analyzer didn't catch it |
||
{ | ||
SourceExtensionConfig *config = | ||
(SourceExtensionConfig *) calloc(1, sizeof(SourceExtensionConfig)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,10 +118,12 @@ stringToInt64(const char *str, int64_t *number) | |
{ | ||
return false; | ||
} | ||
#if LLONG_MAX > INT64_MAX | ||
else if (n < INT64_MIN || n > INT64_MAX) | ||
{ | ||
return false; | ||
} | ||
#endif | ||
|
||
*number = n; | ||
|
||
|
@@ -208,10 +210,12 @@ stringToUInt64(const char *str, uint64_t *number) | |
{ | ||
return false; | ||
} | ||
#if LLONG_MAX > INT64_MAX | ||
else if (n > UINT64_MAX) | ||
{ | ||
return false; | ||
} | ||
#endif | ||
|
||
*number = n; | ||
|
||
|
@@ -507,7 +511,7 @@ IntervalToString(uint64_t millisecs, char *buffer, size_t size) | |
else if (seconds < 10.0) | ||
{ | ||
int s = (int) seconds; | ||
uint64_t ms = millisecs - (1000 * s); | ||
uint64_t ms = millisecs - (1000L * s); | ||
|
||
sformat(buffer, size, "%2ds%03lld", s, (long long) ms); | ||
} | ||
|
@@ -692,7 +696,7 @@ processBufferCallback(const char *buffer, bool error) | |
void | ||
pretty_print_bytes(char *buffer, size_t size, uint64_t bytes) | ||
{ | ||
const char *suffixes[7] = { | ||
const char *suffixes[] = { | ||
"B", /* Bytes */ | ||
"kB", /* Kilo */ | ||
"MB", /* Mega */ | ||
|
@@ -705,7 +709,7 @@ pretty_print_bytes(char *buffer, size_t size, uint64_t bytes) | |
uint sIndex = 0; | ||
long double count = bytes; | ||
|
||
while (count >= 10240 && sIndex < 7) | ||
while (count >= 10240 && sIndex < (sizeof(suffixes) / sizeof(char) - 1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can understand why we want to remove hard coded array sizes. However, I have some questions:
|
||
{ | ||
sIndex++; | ||
count /= 1024; | ||
|
@@ -766,7 +770,7 @@ pretty_print_bytes_per_second(char *buffer, size_t size, uint64_t bytes, | |
void | ||
pretty_print_count(char *buffer, size_t size, uint64_t number) | ||
{ | ||
const char *suffixes[7] = { | ||
const char *suffixes[] = { | ||
"", /* units */ | ||
"thousands", /* 10^3 */ | ||
"million", /* 10^6 */ | ||
|
@@ -793,7 +797,7 @@ pretty_print_count(char *buffer, size_t size, uint64_t number) | |
long double count = number; | ||
|
||
/* issue 1234 million rather than 1 billion or 1.23 billion */ | ||
while (count >= 10000 && sIndex < 7) | ||
while (count >= 10000 && sIndex < (sizeof(suffixes) / sizeof(char) - 1)) | ||
{ | ||
sIndex++; | ||
count /= 1000; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this change here is a mistake.