]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Avoid a crash in source_cache::extract_lines
authorTom Tromey <tromey@adacore.com>
Fri, 8 Mar 2019 20:59:27 +0000 (13:59 -0700)
committerTom Tromey <tromey@adacore.com>
Thu, 14 Mar 2019 11:51:11 +0000 (05:51 -0600)
commit655aeea04784cdc3e4dfbc0801e7be56f9a1ec11
tree274046ee621e2e2f4d14a8038c029713100b3ad3
parentcf2a5276288ce16242a35594db9f61fa9e8f5120
Avoid a crash in source_cache::extract_lines

If the first requested line is larger than the number of lines in the
source buffer, source_cache::extract_lines could crash, because it
would try to pass string::npos" to string::substr.

This patch avoids the crash by checking for this case.

This version of the patch changes get_source_lines to return
std::string.

2019-03-14  Tom Tromey  <tromey@adacore.com>

* source-cache.h (class source_cache) <get_source_lines>: Return
std::string.
* source-cache.c (source_cache::extract_lines): Handle case where
first_pos==npos.  Return std::string.
(source_cache::get_source_lines): Update.
gdb/ChangeLog
gdb/source-cache.c
gdb/source-cache.h