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

Improve code according to the static analyzer report #821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SeleznevPavel
Copy link

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.

@SeleznevPavel SeleznevPavel force-pushed the bugfix/static-analyzer-pangolin branch from 9c223ff to e8e3029 Compare June 23, 2024 15:07
Copy link
Contributor

@hanefi hanefi left a 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:

  1. 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.
  2. 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)
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Author

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))
Copy link
Contributor

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:

  1. Why do you need the -1?
  2. Why did you divide by sizeof(char) where elements are actually char*?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants