From 4b5af127d4bc031e116862b224a10350d16e780a Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Fri, 10 Jan 2025 13:55:15 +0100 Subject: [PATCH] Fix crash on break on invalid filename --- breakpoints.cpp | 5 +++-- debugger.cpp | 2 +- debugger.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/breakpoints.cpp b/breakpoints.cpp index 45e930b..e01dcb3 100644 --- a/breakpoints.cpp +++ b/breakpoints.cpp @@ -229,11 +229,12 @@ BreakpointManager::ParseBreakpointLine(const std::string& input, std::string* fi std::string partial_filename = input.substr(0, sep_offs); // the user may have given a partial filename (e.g. without a path), so // walk through all files to find a match - *filename = debugger_->FindFileByPartialName(partial_filename); - if ((*filename).empty()) { + const char* found_filename = debugger_->FindFileByPartialName(partial_filename); + if (!found_filename) { std::cout << "Invalid filename.\n"; return ""; } + *filename = found_filename; return input.substr(sep_offs + 1); } return input; diff --git a/debugger.cpp b/debugger.cpp index c560d6f..f7252ad 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -345,7 +345,7 @@ Debugger::DumpStack() context_->DestroyFrameIterator(frames); } -std::string +const char* Debugger::FindFileByPartialName(const std::string partialname) { // the user may have given a partial filename (e.g. without a path), so diff --git a/debugger.h b/debugger.h index 19776ec..e5f629a 100644 --- a/debugger.h +++ b/debugger.h @@ -132,7 +132,7 @@ class Debugger { void DumpStack(); void PrintCurrentPosition(); - std::string FindFileByPartialName(const std::string partialname); + const char* FindFileByPartialName(const std::string partialname); private: std::shared_ptr ResolveCommandString(const std::string command);