Clean-up: common: fix -Wshadow errors in event-field-value.c
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 31 Mar 2021 18:44:06 +0000 (14:44 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 13 Apr 2021 20:21:58 +0000 (16:21 -0400)
We get this when building with -Wshadow:

      CC       event-field-value.lo
    In file included from /home/simark/src/lttng-tools/src/common/error.h:19,
                     from /home/simark/src/lttng-tools/src/common/event-field-value.c:17:
    /home/simark/src/lttng-tools/src/common/event-field-value.c: In function ‘lttng_event_field_value_unsigned_int_get_value’:
    /home/simark/src/lttng-tools/src/common/macros.h:55:42: error: declaration of ‘__ptr’ shadows a previous local [-Werror=shadow]
       55 |   const typeof(((type *)NULL)->member) * __ptr = (ptr); \
          |                                          ^~~~~
    /home/simark/src/lttng-tools/src/common/event-field-value.c:390:10: note: in expansion of macro ‘container_of’
      390 |   *val = container_of(
          |          ^~~~~~~~~~~~
    /home/simark/src/lttng-tools/src/common/event-field-value.c:391:5: note: in expansion of macro ‘container_of’
      391 |     container_of(field_val,
          |     ^~~~~~~~~~~~
    /home/simark/src/lttng-tools/src/common/macros.h:55:42: note: shadowed declaration is here
       55 |   const typeof(((type *)NULL)->member) * __ptr = (ptr); \
          |                                          ^~~~~
    /home/simark/src/lttng-tools/src/common/event-field-value.c:390:10: note: in expansion of macro ‘container_of’
      390 |   *val = container_of(
          |          ^~~~~~~~~~~~

This is because of the nested use of container_of, causing two temporary
__ptr variables to be declared in the same scope. Fix it by assigning
results of container_of to temporary variables. I think the temporary
variables make it more readable anyway, showing what's going on.

Change-Id: I7b66bc40227a4c76b7f5416a911dcdc696f4efc8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/event-field-value.c

index b571f6246430ad7ba667b9d24c15a519fc7b7d31..b57c7c53e206fc249de919575583e04234aef923 100644 (file)
@@ -387,13 +387,19 @@ lttng_event_field_value_unsigned_int_get_value(
                                parent)->val;
                break;
        case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM:
-               *val = container_of(
-                               container_of(field_val,
-                                       const struct lttng_event_field_value_enum,
-                                       parent),
-                               const struct lttng_event_field_value_enum_uint,
-                               parent)->val;
+       {
+               const struct lttng_event_field_value_enum *field_val_enum = container_of(
+                               field_val,
+                               const struct lttng_event_field_value_enum,
+                               parent);
+               const struct lttng_event_field_value_enum_uint
+                               *field_val_enum_uint = container_of(
+                                               field_val_enum,
+                                               const struct lttng_event_field_value_enum_uint,
+                                               parent);
+               *val = field_val_enum_uint->val;
                break;
+       }
        default:
                status = LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID;
                goto end;
@@ -423,13 +429,19 @@ lttng_event_field_value_signed_int_get_value(
                                parent)->val;
                break;
        case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM:
-               *val = container_of(
-                               container_of(field_val,
-                                       const struct lttng_event_field_value_enum,
-                                       parent),
-                               const struct lttng_event_field_value_enum_int,
-                               parent)->val;
+       {
+               const struct lttng_event_field_value_enum *field_val_enum = container_of(
+                               field_val,
+                               const struct lttng_event_field_value_enum,
+                               parent);
+               const struct lttng_event_field_value_enum_int
+                               *field_val_enum_uint = container_of(
+                                               field_val_enum,
+                                               const struct lttng_event_field_value_enum_int,
+                                               parent);
+               *val = field_val_enum_uint->val;
                break;
+       }
        default:
                status = LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID;
                goto end;
This page took 0.035101 seconds and 4 git commands to generate.