waneck / haxe-genc

20 stars 2 forks source link

Respect boolean short-circuit when sanitizing #24

Closed Simn closed 10 years ago

Simn commented 11 years ago
class Main {
    static public function main() {
        var s:String = null;
        if (s != null && getChar(s)) {

        }
    }

    static function getChar(s:String) {
        return s.indexOf("s") == 1;
    }
}

The main compiles as:

void Main_main(){
    String* s;int _g16;
    s = NULL;
    _g16 = Main_getChar(s);
    if(String_equals(s,NULL) != 1 && _g16){
        }
}

This causes a crash because Main_getChar(s) is evaluated.

Simn commented 10 years ago

This now compiles correctly:

void Main_main(){
    String* s;
    s = NULL;
    if(((String_equals(s,NULL) != 1) ? Main_getChar(s) : 0)){
        }
}