From: Simon Marchi Date: Wed, 31 Mar 2021 18:44:06 +0000 (-0400) Subject: Clean-up: common: fix -Wshadow errors in event-field-value.c X-Git-Tag: v2.13.0-rc1~133 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=9918e00a8a03011c145bb45c35b183c94ec69023 Clean-up: common: fix -Wshadow errors in event-field-value.c 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 Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/event-field-value.c b/src/common/event-field-value.c index b571f6246..b57c7c53e 100644 --- a/src/common/event-field-value.c +++ b/src/common/event-field-value.c @@ -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;