AmokHuginnsson / replxx

A readline and libedit replacement that supports UTF-8, syntax highlighting, hints and Windows and is BSD licensed.
Other
691 stars 108 forks source link

Out of bounds vector access #61

Closed fnxweb closed 4 years ago

fnxweb commented 4 years ago

I accidentally caught a Visual Studio debug assertion (not exactly sure what I typed) but it highlighted a possible out of bounds vector access in replxx_impl.cxx (line 1871 at time of writing):

} else if ( ( dp._direction > 0 ) ? ( historySearchIndex < _history.size() ) : ( historySearchIndex > 0 ) ) {
  historySearchIndex += dp._direction;
  activeHistoryLine.assign( _history[historySearchIndex] );

_direction was incremented to have the value of the actual size of the vector, thus going out; I think the check in the if should be: ( historySearchIndex < _history.size() - 1 )

AmokHuginnsson commented 4 years ago

Thank you for this report.

I have applied suggested fix in 8915f96e7e02d6a85bd38ca2bde38f8848656066.