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

Referencing local variable before assignment is safe inside sizeof #3575

Closed
Celelibi opened this issue May 5, 2020 · 3 comments · Fixed by #3631
Closed

Referencing local variable before assignment is safe inside sizeof #3575

Celelibi opened this issue May 5, 2020 · 3 comments · Fixed by #3631

Comments

@Celelibi
Copy link
Contributor

Celelibi commented May 5, 2020

Referencing a variable before it is assigned to anything is usually a bad idea.
It is, however, perfectly valid to do so inside the sizeof operator. It's even a common pattern in C when using malloc / calloc.

This program produce a warning, while it should probably not.

def main():
    cdef int x
    print(sizeof(x))

main()
@scoder
Copy link
Contributor

scoder commented May 5, 2020

True. Can't say how difficult it is to fix, though. Maybe we could special-case sizeof(), and probably also typeid(), varargs() and maybe others(?) in the control flow analysis somehow, so that they won't consider the variable an actual usage.

Celelibi added a commit to Celelibi/cython that referenced this issue May 24, 2020
Closes cython#3575

Signed-off-by: Celelibi <celelibi@gmail.com>
Celelibi added a commit to Celelibi/cython that referenced this issue May 24, 2020
Closes cython#3575

Signed-off-by: Celelibi <celelibi@gmail.com>
@Celelibi
Copy link
Contributor Author

I am not sure what you mean by varargs().

@scoder
Copy link
Contributor

scoder commented May 25, 2020

I am not sure what you mean by varargs().

Sorry, I meant va_start() and friends in stdarg.h. But I just noticed that we're not currently providing those declarations anyway, so it's not something to add in this PR for now.

@scoder scoder added this to the 0.29.19 milestone May 25, 2020
Celelibi added a commit to Celelibi/cython that referenced this issue May 25, 2020
Closes cython#3575

Signed-off-by: Celelibi <celelibi@gmail.com>
@scoder scoder modified the milestones: 0.29.19, 0.29.20 May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants