Ticket #714 (reopened defect)

Opened 22 months ago

Last modified 13 months ago

Misleading warnings: "local variable referenced before assignment"

Reported by: nikratio Owned by: vitja
Priority: major Milestone: 0.17
Component: Error Reporting Keywords:
Cc: nikratio

Description

Starting with Cython 0.15, constructions like

def setxattr(path, name, value):
    '''Set extended attribute'''

    cdef int ret
    cdef Py_ssize_t len_
    cdef char *cvalue, *cname, *cpath

    PyBytes_AsStringAndSize(value, &cvalue, &len_)
    #...

produce warnings of the form

warning: /home/nikratio/projekte/llfuse/src/fuse_api.pxi:58:42: local variable 'cvalue' referenced before assignment
warning: /home/nikratio/projekte/llfuse/src/fuse_api.pxi:58:49: local variable 'len_' referenced before assignment

...but obviously the code is correct. I'm not sure if warning about uninitialized values when one just passes a pointer to that variable really catches more bugs than it produces false positives.

Change History

Changed 22 months ago by scoder

  • component changed from Code Generation to Error Reporting
  • summary changed from Misleading "local variable referenced before assignment" to Misleading warnings: "local variable referenced before assignment"

Changed 22 months ago by vitja

I'm not sure how to fix this correctly. First idea is: mark names with ampersand as safe.

  • &a - we just take address of a
  • &a[0] - this is unsafe

Changed 21 months ago by vitja

  • owner changed from somebody to vitja

Changed 21 months ago by vitja

  • status changed from new to closed
  • resolution set to fixed

Changed 21 months ago by vitja

  • milestone changed from wishlist to 0.15.1

Changed 21 months ago by nikratio

  • cc nikratio added

Changed 19 months ago by nikratio

  • status changed from closed to reopened
  • resolution fixed deleted

I don't think this has been fixed completely:

$ cython -Wextra mylib.pyx
warning: mylib.pyx:7:13: local variable 'i' might be referenced before assignment

$ cat mylib.pyx 
cdef extern from "*":
    void init_i(int* i)

cdef test():
    cdef int i

    init_i(&i)

$ cython --version
Cython version 0.15.1

Changed 13 months ago by mark

  • milestone changed from 0.15.1 to 0.17
Note: See TracTickets for help on using tickets.