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:47:11 +0000 (05:47 -0600)
commit3b336828de914a39741339b5341b88aa003d7225
tree78239e64e7f5b42b525f31c45c9deeed2a64489a
parentd085f98901ccd6c9764b93d3983f3c7797addc4f
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.

gdb/ChangeLog
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
This page took 0.026313 seconds and 4 git commands to generate.