kaitai_struct_cpp_stl_runtime
kaitai_struct_cpp_stl_runtime copied to clipboard
Validation exceptions stores references to temporary variables
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"));
}
}