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

Validation exceptions stores references to temporary variables #71

Open
Mingun opened this issue Apr 14, 2024 · 0 comments
Open

Validation exceptions stores references to temporary variables #71

Mingun opened this issue Apr 14, 2024 · 0 comments

Comments

@Mingun
Copy link

Mingun commented Apr 14, 2024

If you look at generated code for valid_*.ksy tests you will see that exceptions are created using temporary values from getters of just constants. The program will crash if you try to get the result from the exception.

Some examples:

// expr: _ == 1
// expr: _ < -190 or _ > -190
void valid_fail_expr_t::_read() {
    m_foo = m__io->read_u1();
    {
        uint8_t _ = foo();
        if (!(_ == 1)) {
            // reference to temporary returned by foo()
            throw kaitai::validation_expr_error<uint8_t>(foo(), _io(), std::string("/seq/0"));
        }
    }
    m_bar = m__io->read_s2le();
    {
        int16_t _ = bar();
        if (!( ((_ < -190) || (_ > -190)) )) {
            // reference to temporary returned by bar()
            throw kaitai::validation_expr_error<int16_t>(bar(), _io(), std::string("/seq/1"));
        }
    }
}
// max: 12
void valid_fail_max_int_t::_read() {
    m_foo = m__io->read_u1();
    if (!(foo() <= 12)) {
        // reference to constant 12
        throw kaitai::validation_greater_than_error<uint8_t>(12, foo(), _io(), std::string("/seq/0"));
    }
}
// min: 123
void valid_fail_min_int_t::_read() {
    m_foo = m__io->read_u1();
    if (!(foo() >= 123)) {
        // reference to constant 123
        throw kaitai::validation_less_than_error<uint8_t>(123, foo(), _io(), std::string("/seq/0"));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant