Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum conversion: fix loop variable captured in closure #2298

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

alban
Copy link
Member

@alban alban commented Dec 14, 2023

When iterating over the btf types, the loop variable was captured in the getter() closure. This caused enumSetter() to use the wrong btf type to get the enum value.

To avoid this problem, this patch makes sure that the closures use a copy of the loop variable.

Fixes: dcf979c

Problem discovered when trying to implement enums in the dns gadget: #2204 (comment)

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thanks for the quick fix.

When iterating over the btf types, the loop variable was captured in the
getter() closure. This caused enumSetter() to use the wrong btf type to
get the enum value.

To avoid this problem, this patch makes sure that the closures use a
copy of the loop variable.

Fixes: dcf979c

Signed-off-by: Alban Crequy <albancrequy@linux.microsoft.com>
Copy link
Member

@burak-ok burak-ok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, too. Thanks for spotting this

@mauriciovasquezbernal
Copy link
Member

Rebasing to pick #2300 up.

@mauriciovasquezbernal mauriciovasquezbernal merged commit 3184a49 into main Dec 15, 2023
50 checks passed
@mauriciovasquezbernal mauriciovasquezbernal deleted the alban_loop_variable_capture1 branch December 15, 2023 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants