-
Notifications
You must be signed in to change notification settings - Fork 78
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?
Improve code according to the static analyzer report #821
Conversation
9c223ff
to
e8e3029
Compare
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.
Thanks for this PR. Some high level comments:
- We do not really update our libraries directly. If there is something wrong with them, they should be fixed in relevant upstream sources. You can see details on readme files in those directories.
- We now use libgc, and no longer need
free()
calls.
@@ -831,7 +831,7 @@ pgsql_retry_open_connection(PGSQL *pgsql) | |||
} | |||
} | |||
|
|||
if (!connectionOk && pgsql->connection != NULL) | |||
if (!connectionOk || pgsql->connection != NULL) |
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.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
static analyzer didn't catch it
@@ -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 comment
The 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:
- Why do you need the
-1
? - Why did you divide by
sizeof(char)
where elements are actuallychar*
?
We have a static analyzer report on the Postgres kernel and various components. We plan to publish this report to the community in the form of proposals for pull requests. This pull request is in progress and will be updated. I will aks later for review and merge approval.