dxx-rebirth/similar
Kp 0fd80b12df Prevent out-of-bounds read when sorting segment sides
GCC 6 `std::sort` sometimes compares an element to itself.  For a normal
implementation of comparison, this is useless, but not harmful.  The
render comparison predicate relies on accessing A[B[a][b]] when
comparing `a` and `b`.  Array `B` has `-1` in positions where `a == b`,
which causes an access to `A[-1]`, which is undefined behavior.  This
crashes when using _GLIBCXX_DEBUG:

    Error: attempt to subscript container with out-of-bounds index -1, but
    container only holds 8 elements.

    Objects involved in the operation:
	sequence "this" @ 0x0x335adf0 {
	  type = std::__debug::array<int, 8ul>::_Array_check_subscript<8ul>;
	}

Since this is undefined behavior, non-debug builds might also misbehave.
Current data layouts make it likely that the failure would not have
externally observable consequences.

Prevent the invalid access by short-circuiting the result if `a == b`.
2017-02-11 21:42:43 +00:00
..
2d Pass canvas to gr_set_curfont 2017-02-11 21:42:38 +00:00
3d Pass canvas to g3_check_and_draw_poly 2017-02-11 21:42:42 +00:00
arch Pass canvas to LINE_SPACING 2017-02-11 21:42:42 +00:00
editor Pass canvas to g3_check_and_draw_poly 2017-02-11 21:42:42 +00:00
main Prevent out-of-bounds read when sorting segment sides 2017-02-11 21:42:43 +00:00
misc Fix failure to unmap custom hogs 2016-12-17 18:39:18 +00:00