Changeset 279 in openpam for trunk


Ignore:
Timestamp:
Feb 17, 2004, 11:13:13 AM (16 years ago)
Author:
Dag-Erling Smørgrav
Message:

Make the ENTER*() and RETURN*() macros safe from side-effects, and
solve the "dereferencing NULL pointer" warning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/openpam_impl.h

    r251 r279  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_impl.h#28 $
     34 * $P4: //depot/projects/openpam/lib/openpam_impl.h#29 $
    3535 */
    3636
     
    138138#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering")
    139139#define ENTERI(i) do { \
    140         if ((i) > 0 && (i) < PAM_NUM_ITEMS) \
    141                 openpam_log(PAM_LOG_DEBUG, "entering: %s", _pam_item_name[i]); \
     140        int _i = (i); \
     141        if (_i > 0 && _i < PAM_NUM_ITEMS) \
     142                openpam_log(PAM_LOG_DEBUG, "entering: %s", _pam_item_name[_i]); \
    142143        else \
    143                 openpam_log(PAM_LOG_DEBUG, "entering: %d", (i)); \
     144                openpam_log(PAM_LOG_DEBUG, "entering: %d", _i); \
    144145} while (0)
    145146#define ENTERN(n) do { \
    146         openpam_log(PAM_LOG_DEBUG, "entering: %d", (n)); \
     147        int _n = (n); \
     148        openpam_log(PAM_LOG_DEBUG, "entering: %d", _n); \
    147149} while (0)
    148150#define ENTERS(s) do { \
    149         if ((s) == NULL) \
     151        const char *_s = (s); \
     152        if (_s == NULL) \
    150153                openpam_log(PAM_LOG_DEBUG, "entering: NULL"); \
    151154        else \
    152                 openpam_log(PAM_LOG_DEBUG, "entering: '%s'", (s)); \
     155                openpam_log(PAM_LOG_DEBUG, "entering: '%s'", _s); \
    153156} while (0)
    154157#define RETURNV() openpam_log(PAM_LOG_DEBUG, "returning")
    155158#define RETURNC(c) do { \
    156         if ((c) >= 0 && (c) < PAM_NUM_ERRORS) \
    157                 openpam_log(PAM_LOG_DEBUG, "returning %s", _pam_err_name[c]); \
     159        int _c = (c); \
     160        if (_c >= 0 && _c < PAM_NUM_ERRORS) \
     161                openpam_log(PAM_LOG_DEBUG, "returning %s", _pam_err_name[_c]); \
    158162        else \
    159                 openpam_log(PAM_LOG_DEBUG, "returning %d!", (c)); \
    160         return (c); \
     163                openpam_log(PAM_LOG_DEBUG, "returning %d!", _c); \
     164        return (_c); \
    161165} while (0)
    162166#define RETURNN(n) do { \
    163         openpam_log(PAM_LOG_DEBUG, "returning %d", (n)); \
    164         return (n); \
     167        int _n = (n); \
     168        openpam_log(PAM_LOG_DEBUG, "returning %d", _n); \
     169        return (_n); \
    165170} while (0)
    166171#define RETURNP(p) do { \
    167         if ((p) == NULL) \
     172        const void *_p = (p); \
     173        if (_p == NULL) \
    168174                openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
    169175        else \
    170                 openpam_log(PAM_LOG_DEBUG, "returning %p", (p)); \
     176                openpam_log(PAM_LOG_DEBUG, "returning %p", _p); \
    171177        return (p); \
    172178} while (0)
    173179#define RETURNS(s) do { \
    174         if ((s) == NULL) \
     180        const char *_s = (s); \
     181        if (_s == NULL) \
    175182                openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
    176183        else \
    177                 openpam_log(PAM_LOG_DEBUG, "returning '%s'", (s)); \
    178         return (s); \
     184                openpam_log(PAM_LOG_DEBUG, "returning '%s'", _s); \
     185        return (_s); \
    179186} while (0)
    180187#else
Note: See TracChangeset for help on using the changeset viewer.