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

Setting the same variable used in subsequent if cause the comparison to fail #411

Closed
jrbasso opened this issue May 22, 2014 · 2 comments
Closed
Labels

Comments

@jrbasso
Copy link

jrbasso commented May 22, 2014

Zep code:

namespace Xxx;

class Buggy {

    public static function bugCompare() {
        var str;

        let str = strtolower("testing");
        if str === "wrong testing" {
            let str = "NOK";
        } else {
            if str === "another testing" {
                let str = "NOK";
            } else {
                if str === "testing" {
                    let str = "OK";
                } else {
                    let str = "NOK";
                }
            }
        }
        return str;
    }
}

C code:

#ifdef HAVE_CONFIG_H
#include "../ext_config.h"
#endif

#include <php.h>
#include "../php_ext.h"
#include "../ext.h"

#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>

#include "kernel/main.h"
#include "kernel/memory.h"
#include "kernel/string.h"
#include "kernel/operators.h"

ZEPHIR_INIT_CLASS(Xxx_Buggy) {
    ZEPHIR_REGISTER_CLASS(Xxx, Buggy, xxx, buggy, xxx_buggy_method_entry, 0);
    return SUCCESS;
}

PHP_METHOD(Xxx_Buggy, bugCompare) {
    zval *str, _0;

    ZEPHIR_MM_GROW();

    ZEPHIR_INIT_VAR(str);
    ZEPHIR_SINIT_VAR(_0);
    ZVAL_STRING(&_0, "testing", 0);
    zephir_fast_strtolower(str, &_0);
    if (ZEPHIR_IS_STRING(str, "wrong testing")) {
        ZEPHIR_INIT_BNVAR(str);
        ZVAL_STRING(str, "NOK", 1);
    } else {
        if (ZEPHIR_IS_STRING(str, "another testing")) {
            ZEPHIR_INIT_BNVAR(str);
            ZVAL_STRING(str, "NOK", 1);
        } else {
            ZEPHIR_INIT_BNVAR(str);
            if (ZEPHIR_IS_STRING(str, "testing")) {
                ZVAL_STRING(str, "OK", 1);
            } else {
                ZVAL_STRING(str, "NOK", 1);
            }
        }
    }
    RETURN_CCTOR(str);
}

Return expected: OK
Returned: NOK

This is the part where mess the comparison:

ZEPHIR_INIT_BNVAR(str);
if (ZEPHIR_IS_STRING(str, "testing")) {

Zephir is initializing the same variable that will be tested.

@ovr ovr added the bug label May 22, 2014
@ovr
Copy link
Contributor

ovr commented May 22, 2014

Marked this as bug, thx you for report :) will try to fix this now

ovr added a commit to ovr/zephir that referenced this issue May 22, 2014
ovr added a commit to ovr/zephir that referenced this issue May 22, 2014
@ovr
Copy link
Contributor

ovr commented May 22, 2014

Fixed, w8 @phalcon review :)

@ovr ovr closed this as completed in 05ac183 May 27, 2014
ovr added a commit that referenced this issue May 27, 2014
Fix #411 Issue about SkipVariantInit bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants