dfhack icon indicating copy to clipboard operation
dfhack copied to clipboard

result of `binsearch_index` used without validation in `Eventmgr.cpp`

Open ab9rf opened this issue 10 months ago • 0 comments

    size_t idx = df::report::binsearch_index(reports, lastReportUnitAttack, false);
    // returns the index to the key equal to or greater than the key provided
    idx = reports[idx]->id == lastReportUnitAttack ? idx + 1 : idx; // we need the index after (where the new stuff is)

idx may be -1 here if the report ID was not found in the relevant index, however, this code uses idx without validating the results of the search function

this is another one of those cases where we're assuming DF data structures are well-ordered, and getting burned because they're not

related discord discussion

ab9rf avatar Apr 19 '25 04:04 ab9rf