From 4f657a3ecdef2e57748973b9b0ec8581227a1f14 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Thu, 22 Apr 2021 00:36:53 -0700 Subject: [PATCH] :bug: GetLogs Seg fault out range seg --- config.json | 7 ------- include/bank.hpp | 21 ++++++++++++--------- main.cpp | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/config.json b/config.json index 5576c78..eeadc3c 100644 --- a/config.json +++ b/config.json @@ -4,13 +4,6 @@ "address": "0.0.0.0", "port": 80, "https": false - }, - { - "address": "0.0.0.0", - "port": 443, - "https": true, - "cert": "", - "key": "" } ] } \ No newline at end of file diff --git a/include/bank.hpp b/include/bank.hpp index 14720b3..1740b90 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -161,18 +161,21 @@ public: { Json::Value res = -1; users.if_contains(name, [&res](const User &u) { - uint32_t j; - for (uint32_t i = u.log.data.size() - 1; i > 0; --i) + if (u.log.data.size()) { - j = u.log.data.size() - 1 - i; - if (!u.log.data[i].amount) + uint32_t j; + for (uint32_t i = u.log.data.size() - 1; i > 0; --i) { - return; + j = u.log.data.size() - 1 - i; + if (!u.log.data[i].amount) + { + return; + } + res[j]["to"] = u.log.data[i].to; + res[j]["from"] = u.log.data[i].from; + res[j]["amount"] = u.log.data[i].amount; + res[j]["time"] = (Json::UInt64)u.log.data[i].time; } - res[j]["to"] = u.log.data[i].to; - res[j]["from"] = u.log.data[i].from; - res[j]["amount"] = u.log.data[i].amount; - res[j]["time"] = (Json::UInt64)u.log.data[i].time; } }); return res; diff --git a/main.cpp b/main.cpp index 60f994c..2b2d69d 100644 --- a/main.cpp +++ b/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char **argv) [](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) { resp->addHeader("Access-Control-Allow-Origin", "*"); }); - app().loadConfigFile("../config.json").registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run(); + app().loadConfigFile("../config.json").registerController(API).setThreadNum(std::stoul(argv[3])).run(); return 0; } \ No newline at end of file