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

Tests on equalp are always true #1276

Merged
merged 1 commit into from
Jan 24, 2019
Merged

Tests on equalp are always true #1276

merged 1 commit into from
Jan 24, 2019

Conversation

gsjaardema
Copy link
Contributor

If equalp is NULL, then the function returns early, so all subsequent tests on equalp are not needed.

If `equalp` is NULL, then the function returns early, so all subsequent tests on `equalp` are not needed.
@@ -52,20 +52,17 @@ NC4_inq_type_equal(int ncid1, nc_type typeid1, int ncid2,
if ((typeid1 <= NC_STRING && typeid2 > NC_STRING) ||
(typeid2 <= NC_STRING && typeid1 > NC_STRING))
{
if (equalp) *equalp = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good catch, thanks!

I would actually rewrite this so that a NULL equalp does not return NC_NOERR immediately. That's not how our other inq functions work. Normally, even if the user provides a NULL where we would put the answer, we still go through all the work before not doing anything. ;-)

That is, for this function, I would expect that even if I provided NULL, I would get NC_EBADTYPE if one of the types is not found.

The way to do this is to have a local variable "equal" and then, at the end of the function, set equalp if it was provided.

@WardF WardF merged commit 1ab5392 into Unidata:master Jan 24, 2019
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.

3 participants