fix: shadowed local variable in macros (-Wshadow)
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 24 Mar 2021 21:03:46 +0000 (17:03 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Mar 2021 18:02:43 +0000 (14:02 -0400)
Add a prefix to the local variable names defined in the PERROR macro to
reduce the risk of shadowing variables with generic names.

Remove the local variable '____ptr_ret' in the shmp_index macro

Change-Id: I5d33e8eb4c760ffb527ac02cf8901105b500b28d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/usterr-signal-safe.h
libringbuffer/shm.h

index 868a0d8b81257d186cd5a788e40c1891058c52b7..50137617f6b99c494b22d90df7b54114c6dace14 100644 (file)
@@ -100,9 +100,11 @@ do {                                                                       \
 #define PERROR(call, args...)                                          \
        do {                                                            \
                if (ust_err_debug_enabled()) {                          \
-                       char buf[200] = "Error in strerror_r()";        \
-                       strerror_r(errno, buf, sizeof(buf));            \
-                       ERRMSG("Error: " call ": %s", ## args, buf);    \
+                       char perror_buf[200] = "Error in strerror_r()"; \
+                       strerror_r(errno, perror_buf,                   \
+                                       sizeof(perror_buf));            \
+                       ERRMSG("Error: " call ": %s", ## args,          \
+                                       perror_buf);                    \
                }                                                       \
        } while(0)
 #else
@@ -112,10 +114,12 @@ do {                                                                      \
 #define PERROR(call, args...)                                          \
        do {                                                            \
                if (ust_err_debug_enabled()) {                          \
-                       char *buf;                                      \
-                       char tmp[200];                                  \
-                       buf = strerror_r(errno, tmp, sizeof(tmp));      \
-                       ERRMSG("Error: " call ": %s", ## args, buf);    \
+                       char *perror_buf;                               \
+                       char perror_tmp[200];                           \
+                       perror_buf = strerror_r(errno, perror_tmp,      \
+                                       sizeof(perror_tmp));            \
+                       ERRMSG("Error: " call ": %s", ## args,          \
+                                       perror_buf);                    \
                }                                                       \
        } while(0)
 #endif
index 64507463dadb8cc0fe1d2f9e7bc5d36a09546179..dab0b68d561b9ce1a05df0bc421f5ebb9a20e144 100644 (file)
@@ -64,12 +64,8 @@ char *_shmp_offset(struct shm_object_table *table, struct shm_ref *ref,
        return &obj->memory_map[ref_offset];
 }
 
-#define shmp_index(handle, ref, index)                                 \
-       ({                                                              \
-               __typeof__((ref)._type) ____ptr_ret;                    \
-               ____ptr_ret = (__typeof__(____ptr_ret)) _shmp_offset((handle)->table, &(ref)._ref, index, sizeof(*____ptr_ret));        \
-               ____ptr_ret;                                            \
-       })
+#define shmp_index(handle, ref, index) \
+       ((__typeof__((ref)._type)) _shmp_offset((handle)->table, &(ref)._ref, index, sizeof(*((ref)._type))))
 
 #define shmp(handle, ref)      shmp_index(handle, ref, 0)
 
This page took 0.026553 seconds and 4 git commands to generate.