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

xdr_destroy and XDR_CONTROL should be expressions, not statements #29

Open
dmhayden opened this issue Feb 4, 2023 · 0 comments
Open

Comments

@dmhayden
Copy link

dmhayden commented Feb 4, 2023

xdr_destroy and XDR_CONTROL are defined as "if" statements in xdr.h, but they should be expressions.
#define xdr_destroy(xdrs)
if ((xdrs)->x_ops->x_destroy)
(*(xdrs)->x_ops->x_destroy)(xdrs)

As an "if" statement, xdr_destroy() can't appear in the increment clause of a "for" statement:
for (cond; test; xdr_destroy(xp)) { ... } // syntax error

Much worse, it can cause unexpected results when used within an if statement. Consider:
if (cond)
xdr_destroy(xdrs);
else
oops();

If xdrs->x_ops->x_destroy is NULL, then oops() will be called, which is not what the programmer would expect.

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

No branches or pull requests

1 participant