linuxbox2 / ntirpc

New development on tirpc
Other
24 stars 96 forks source link

xdr_destroy and XDR_CONTROL should be expressions, not statements #29

Open dmhayden opened 1 year ago

dmhayden commented 1 year ago

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.