Skip to content

Commit

Permalink
Add octal fix in GetInt32 function
Browse files Browse the repository at this point in the history
  • Loading branch information
DendoD96 committed Jun 29, 2021
1 parent 4f2b880 commit d5bcb6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/gnb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <utils/options.hpp>
#include <utils/yaml_utils.hpp>
#include <yaml-cpp/yaml.h>
#include <string>

static app::CliServer *g_cliServer = nullptr;
static nr::gnb::GnbConfig *g_refConfig = nullptr;
Expand All @@ -42,10 +41,8 @@ static nr::gnb::GnbConfig *ReadConfigYaml()

result->plmn.mcc = yaml::GetInt32(config, "mcc", 1, 999);
yaml::GetString(config, "mcc", 3, 3);
result->plmn.isLongMnc = yaml::GetString(config, "mnc", 2, 3).size() == 3;
auto mncValue = config["mnc"].Scalar();
config["mnc"] = mncValue.erase(0, std::min(mncValue.find_first_not_of('0'), mncValue.size()-1));
result->plmn.mnc = yaml::GetInt32(config, "mnc", 0, 999);
result->plmn.isLongMnc = yaml::GetString(config, "mnc", 2, 3).size() == 3;

result->nci = yaml::GetInt64(config, "nci", 0, 0xFFFFFFFFFll);
result->gnbIdLength = yaml::GetInt32(config, "idLength", 22, 32);
Expand Down
8 changes: 6 additions & 2 deletions src/utils/yaml_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ void AssertHasFields(const YAML::Node &node, const std::vector<std::string> &fie

int GetInt32(const YAML::Node &node, const std::string &name)
{
AssertHasInt32(node, name);
return node[name].as<int>();
auto nodeValue = node[name].Scalar();
nodeValue.erase(0, std::min(nodeValue.find_first_not_of('0'), nodeValue.size()-1));
YAML::Node modifiedNode;
modifiedNode[name] = nodeValue;
AssertHasInt32(modifiedNode, name);
return modifiedNode[name].as<int>();
}

int GetInt32(const YAML::Node &node, const std::string &name, std::optional<int> minValue, std::optional<int> maxValue)
Expand Down

0 comments on commit d5bcb6c

Please sign in to comment.