Ticket #158 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

out-of-order assignment with strings causes segfault

Reported by: hoytak Owned by: Kurt Smith
Priority: critical Milestone: 0.11.1
Component: Code Generation Keywords:
Cc:

Description

Hello,

In cython 1474:7f1b96cad687, the following code results in a segfault. It seems a relevant check for None is omitted because of the assignment, even though the assignment comes later.

def crash():
    print "%s" % s
    cdef str s = "Test"

When crash() is run, the program segfaults. However, the following code segments behave correctly, printing None.

def nocrash():
    print "%s" % s
    cdef str s

and

def nocrash():
    cdef str s = None
    print "%s" % s

Furthermore, assigning None to the s afterwards also causes it to crash (compare above).

def crash(): 
    print "%s" % s
    cdef str s = None

Thanks! --Hoyt

Change History

Changed 6 years ago by scoder

  • milestone changed from wishlist to 0.11

Changed 6 years ago by scoder

There are two problems involved here: one is the missing None check that #166 describes, the other problem is that initial assignments of a cdef apparently fail to take previous usages of the name into account. This is a bit tricky to fix due to Cython's scoping rules: variables exist inside the entire scope (i.e. module/function), regardless of their point of declaration.

Another bug that flow control analysis could potentially fix...

Changed 6 years ago by dagss

Would it be help to simply disable the ability to declare variables after they are used? This is rather easily checked without full flow control analysis.

Changed 6 years ago by robertwb

Yes, I think we should disallow variable declarations after they are used.

Changed 6 years ago by robertwb

  • milestone changed from 0.11 to 0.11.1

Changed 6 years ago by robertwb

  • priority changed from minor to critical

This is a pretty bad bug, but it'll be more than a quick fix and it's not a regression so I don't want to hold up 0.11 for it.

Changed 6 years ago by dagss

  • owner changed from somebody to Kurt Smith

Changed 6 years ago by dagss

Note that this is almost done, there's a patch on the mailing list.

Changed 6 years ago by dagss

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

Changed 6 years ago by dagss

To be clear, this was fixed by making Hoyt's example raise a compilation error.

Note: See TracTickets for help on using tickets.