Skip to content

Spot potential UB  #371

@jcoupey

Description

@jcoupey

Using GCC Undefined Behavior Sanitizer (enable by compiling with -fsanitize=undefined) on an instance of the Solomon benchmark results in:

/usr/include/c++/7/bits/stl_vector.h:816:34: runtime error: reference binding to null pointer of type 'const struct value_type'
structures/vroom/tw_route.cpp:453:43: runtime error: reference binding to null pointer of type 'const struct Break'

Because there is no break in input, the mentioned line:

const auto& b = v.breaks[current_break];

defines a reference to the first element of an empty vector. In that case, the surrounding loop is designed in such a way that this reference is not actually used when the vector is empty, but this is still UB all right.

We should:

  • investigate other potential runtime reports using other input examples
  • fix spotted UB
  • setup a way to check this periodically in the long run

No really sure how to go for that last point because setting -fsanitize=undefined slows down things to such a degree that it is totally not practically usable in dev mode.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions