From: Martin Ling Date: Sat, 7 Dec 2013 16:26:48 +0000 (+0000) Subject: Make RETURN_VALUE macro side effect safe. X-Git-Tag: libserialport-0.1.0~27 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7c1eff54fd240441fb617dcd315117909cf847dd;p=libserialport.git Make RETURN_VALUE macro side effect safe. --- diff --git a/serialport.c b/serialport.c index 45f9773..e42e757 100644 --- a/serialport.c +++ b/serialport.c @@ -173,7 +173,11 @@ void (*sp_debug_handler)(const char *format, ...) = sp_default_debug_handler; #define RETURN_OK() RETURN_CODE(SP_OK); #define RETURN_ERROR(err, msg) do { DEBUG_ERROR(err, msg); return err; } while (0) #define RETURN_FAIL(msg) do { DEBUG_FAIL(msg); return SP_ERR_FAIL; } while (0) -#define RETURN_VALUE(fmt, x) do { DEBUG("%s returning " fmt, __func__, x); return x; } while (0) +#define RETURN_VALUE(fmt, x) do { \ + typeof(x) _x = x; \ + DEBUG("%s returning " fmt, __func__, _x); \ + return _x; \ +} while (0) #define SET_ERROR(val, err, msg) do { DEBUG_ERROR(err, msg); val = err; } while (0) #define SET_FAIL(val, msg) do { DEBUG_FAIL(msg); val = SP_ERR_FAIL; } while (0) #define TRACE(fmt, ...) DEBUG("%s(" fmt ") called", __func__, ##__VA_ARGS__)