From 2a2b0799928816a5b2af7d8b74439e9f9a1d9ebf Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Fri, 18 Mar 2022 00:45:54 -0700 Subject: [PATCH] feat(core): Add error parsing for Tox_Err_Options_New --- src/core/toxoptions.cpp | 6 ++++-- util/include/util/toxcoreerrorparser.h | 1 + util/src/toxcoreerrorparser.cpp | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/toxoptions.cpp b/src/core/toxoptions.cpp index 276bb5554..13e5a4473 100644 --- a/src/core/toxoptions.cpp +++ b/src/core/toxoptions.cpp @@ -21,6 +21,7 @@ #include "src/core/icoresettings.h" #include "src/core/toxlogger.h" +#include "util/toxcoreerrorparser.h" #include @@ -69,9 +70,10 @@ ToxOptions::operator Tox_Options*() std::unique_ptr ToxOptions::makeToxOptions(const QByteArray& savedata, const ICoreSettings& s) { - Tox_Options* tox_opts = tox_options_new(nullptr); + Tox_Err_Options_New err; + Tox_Options* tox_opts = tox_options_new(&err); - if (!tox_opts) { + if (!PARSE_ERR(err) || !tox_opts) { qWarning() << "Failed to create Tox_Options"; return {}; } diff --git a/util/include/util/toxcoreerrorparser.h b/util/include/util/toxcoreerrorparser.h index fa101ac90..ed5e727d6 100644 --- a/util/include/util/toxcoreerrorparser.h +++ b/util/include/util/toxcoreerrorparser.h @@ -58,4 +58,5 @@ namespace ToxcoreErrorParser { bool parseErr(Toxav_Err_Bit_Rate_Set error, int line); bool parseErr(Toxav_Err_Call_Control error, int line); bool parseErr(Toxav_Err_Call error, int line); + bool parseErr(Tox_Err_Options_New error, int line); } // namespace ToxcoreErrorParser diff --git a/util/src/toxcoreerrorparser.cpp b/util/src/toxcoreerrorparser.cpp index ab772dce9..fec7b72d9 100644 --- a/util/src/toxcoreerrorparser.cpp +++ b/util/src/toxcoreerrorparser.cpp @@ -629,3 +629,17 @@ bool ToxcoreErrorParser::parseErr(Toxav_Err_Call error, int line) qCritical() << line << "Unknown Toxav_Err_Call error code:" << error; return false; } + +bool ToxcoreErrorParser::parseErr(Tox_Err_Options_New error, int line) +{ + switch (error) { + case TOX_ERR_OPTIONS_NEW_OK: + return true; + + case TOX_ERR_OPTIONS_NEW_MALLOC: + qCritical() << line << ": Failed to allocate memory."; + return false; + } + qCritical() << line << "Unknown Tox_Err_Options_New error code:" << error; + return false; +}