From 3266d4ef37ea293a6670e10b65bb346e4726a927 Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 12 Feb 2023 15:36:45 -0500 Subject: debughlp.cpp: Use ovectorstream instead of static char array and sprintf --- src/emu/debug/debughlp.cpp | 17 ++++++++++------- src/emu/debug/debughlp.h | 2 +- 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 -- cgit v1.2.3