summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2023-02-12 15:36:45 -0500
committer AJR <ajrhacker@users.noreply.github.com>2023-02-12 15:36:45 -0500
commit3266d4ef37ea293a6670e10b65bb346e4726a927 (patch)
tree7f37dfc4ad9c15c478cc3c80b9cb46ef72e16578 /src
parentf742bef06a424a109070413662bf4e56030b096e (diff)
debughlp.cpp: Use ovectorstream instead of static char array and sprintf
Diffstat (limited to 'src')
-rw-r--r--src/emu/debug/debughlp.cpp17
-rw-r--r--src/emu/debug/debughlp.h2
2 files changed, 11 insertions, 8 deletions
diff --git a/src/emu/debug/debughlp.cpp b/src/emu/debug/debughlp.cpp
index 85de3984020..38dc8cc1a63 100644
--- a/src/emu/debug/debughlp.cpp
+++ b/src/emu/debug/debughlp.cpp
@@ -2023,10 +2023,12 @@ private:
help_map m_help_list;
help_item const *m_uncached_help = std::begin(f_static_help_list);
+ util::ovectorstream m_message_buffer;
+
help_manager() = default;
public:
- char const *find(std::string_view tag)
+ std::string_view find(std::string_view tag)
{
// find a cached exact match if possible
std::string const lower = strmakelower(tag);
@@ -2062,16 +2064,17 @@ public:
if ((m_help_list.end() == next) || (next->first.substr(0, lower.length()) != lower))
return candidate->second;
- // TODO: pointers to static strings are bad, mmmkay?
- static char ambig_message[1024];
- int msglen = std::sprintf(ambig_message, "Ambiguous help request, did you mean:\n");
+ m_message_buffer.clear();
+ m_message_buffer.reserve(1024);
+ m_message_buffer.seekp(0, util::ovectorstream::beg);
+ m_message_buffer << "Ambiguous help request, did you mean:\n";
do
{
- msglen += std::sprintf(&ambig_message[msglen], " help %.*s?\n", int(candidate->first.length()), &candidate->first[0]);
+ util::stream_format(m_message_buffer, " help %.*s?\n", int(candidate->first.length()), &candidate->first[0]);
++candidate;
}
while ((m_help_list.end() != candidate) && (candidate->first.substr(0, lower.length()) == lower));
- return ambig_message;
+ return util::buf_to_string_view(m_message_buffer);
}
// take the first help entry if no matches at all
@@ -2093,7 +2096,7 @@ public:
PUBLIC INTERFACE
***************************************************************************/
-const char *debug_get_help(std::string_view tag)
+std::string_view debug_get_help(std::string_view tag)
{
return help_manager::instance().find(tag);
}
diff --git a/src/emu/debug/debughlp.h b/src/emu/debug/debughlp.h
index 495d674eb0d..9efe12acaca 100644
--- a/src/emu/debug/debughlp.h
+++ b/src/emu/debug/debughlp.h
@@ -21,6 +21,6 @@
***************************************************************************/
// help management
-const char *debug_get_help(std::string_view tag);
+std::string_view debug_get_help(std::string_view tag);
#endif // MAME_EMU_DEBUG_DEBUGHLP_H