8000 Remove redundant NULL pointer checks by rimbi · Pull Request #853 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove redundant NULL pointer checks #853

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

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/bin/pgcopydb/pgcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1676,15 +1676,9 @@ tokenize_archive_list_entry(ArchiveToken *token)
char *ptr = line;

/* advance ptr as long as *ptr is a digit */
for (; ptr != NULL && isdigit(*ptr); ptr++)
for (; isdigit(*ptr); ptr++)
{ }

if (ptr == NULL)
{
log_error("Failed to tokenize Archive Item line: %s", line);
return false;
}

Comment on lines -1682 to -1687
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be happier if you briefly shared why you wanted to remove this check here.

If we keep this check here, we'd have guarantees that there are some more characters after the token that we parsed. I do not really see why we need this check, but I am unsure if it makes sense to remove these lines here.

Copy link
Contributor Author
@rimbi rimbi Jul 23, 2024

Choose a reason for hiding this comment

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

I see. The reason is that there is no way for ptr to be NULL. If it is NULL, then it means that line is also NULL, which means that the preceding isdigit(*line) ends with an error. Once ptr is not NULL, then it can't become NULL by incrementing it with ptr++.

int len = ptr - line + 1;
size_t size = len + 1;
char *buf = (char *) calloc(size, sizeof(char));
Expand Down
Loading
0