Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion '!empty()' failed #223

Open
ast261 opened this issue Jan 19, 2025 · 1 comment
Open

Assertion '!empty()' failed #223

ast261 opened this issue Jan 19, 2025 · 1 comment

Comments

@ast261
Copy link

ast261 commented Jan 19, 2025

Application crashes. Steps to reproduce:

  • initial start
  • On the web page open tab "Log"
  • in HttpServer::methodGet file = "log.json"
  • in base::JSONSerializer::checkAddComma string _json is empty
  • _json.back() is crashing ("Assertion '!empty()' failed."):
    std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::back() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.
@ast261
Copy link
Author

ast261 commented Jan 19, 2025

Possible fix:

diff --git a/src/base/JSONSerializer.h b/src/base/JSONSerializer.h
index 5c88ca3..1bacce7 100644
--- a/src/base/JSONSerializer.h
+++ b/src/base/JSONSerializer.h
@@ -100,10 +100,12 @@ namespace base {
                private:
 
                        void checkAddComma() {
-                               const char c = _json.back();
-                               if (c == '\"' || c == '}' || c == ']' || std::isdigit(c)) {
-                                       _json += ", ";
-                               }
+                if(!_json.empty()) {
+                    const char c = _json.back();
+                    if (c == '\"' || c == '}' || c == ']' || std::isdigit(c)) {
+                        _json += ", ";
+                    }
+                }
                        }
 
                        std::string makeJSONString(const std::string &msg) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant