From fe93261c895b00c762a9e5646e37d2d8d1dbfaab Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 20 Apr 2017 13:37:02 +0900 Subject: [PATCH] Replace sscanf with std::stringstream Change-Id: Ie916e23fe061cab3a3f0b1963a6fe4d94b5c681a --- xmlresource/label_properties_parser.cpp | 34 +++++++++++++++++++++++++-------- xmlresource/layout_parser_helper.cpp | 16 ++++++++++++++-- xmlresource/xml_parser_utils.cpp | 10 +++++++++- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/xmlresource/label_properties_parser.cpp b/xmlresource/label_properties_parser.cpp index 8d06a51..815062e 100644 --- a/xmlresource/label_properties_parser.cpp +++ b/xmlresource/label_properties_parser.cpp @@ -16,11 +16,15 @@ */ #include +#include #include #include "label_properties_parser.h" #include "xml_parser_utils.h" #include "simple_debug.h" #include "put_record.h" + +using namespace std; + static int match_alignment(const char* key) { assert(key != NULL); @@ -308,27 +312,41 @@ class LabelPropertiesParserImpl { a = 0xff; char temp_string[5] = {"0xFF"}; + temp_string[2] = key[2]; temp_string[3] = key[3]; - if (sscanf(temp_string, "%x", &r) <= 0) { - SCLLOG(SclLog::ERROR, "parsing_rgb() has failed."); + stringstream convertor_r(temp_string); + convertor_r >> hex >> r; + if (convertor_r.fail() == true) { + SCLLOG(SclLog::ERROR, "parsing_rgb() [r] has failed."); + r = 0; } temp_string[2] = key[4]; temp_string[3] = key[5]; - if (sscanf(temp_string, "%x", &g) <= 0) { - SCLLOG(SclLog::ERROR, "parsing_rgb() has failed."); + stringstream convertor_g(temp_string); + convertor_g >> hex >> g; + if (convertor_g.fail() == true) { + SCLLOG(SclLog::ERROR, "parsing_rgb() [g] has failed."); + g = 0; } + temp_string[2] = key[6]; temp_string[3] = key[7]; - if (sscanf(temp_string, "%x", &b) <= 0) { - SCLLOG(SclLog::ERROR, "parsing_rgb() has failed."); + stringstream convertor_b(temp_string); + convertor_b >> hex >> b; + if (convertor_b.fail() == true) { + SCLLOG(SclLog::ERROR, "parsing_rgb() [b] has failed."); + b = 0; } temp_string[2] = key[8]; temp_string[3] = key[9]; - if (sscanf(temp_string, "%x", &a) <= 0) { - SCLLOG(SclLog::ERROR, "parsing_rgb() has failed."); + stringstream convertor_a(temp_string); + convertor_a >> hex >> a; + if (convertor_a.fail() == true) { + SCLLOG(SclLog::ERROR, "parsing_rgb() [a] has failed."); + a = 0; } cur_color.r = r; diff --git a/xmlresource/layout_parser_helper.cpp b/xmlresource/layout_parser_helper.cpp index 6d606e8..49b9387 100644 --- a/xmlresource/layout_parser_helper.cpp +++ b/xmlresource/layout_parser_helper.cpp @@ -18,6 +18,7 @@ #include "layout_parser_helper.h" #include #include +#include using namespace std; const string RotationHelper::pcPortrait = "portrait"; @@ -437,11 +438,22 @@ const string INTTypeHelper::toString(const int val) { } const int INTTypeHelper::Int(const string str) { int val = 0; - sscanf(str.c_str(), "%d", &val); + stringstream convertor(str); + + convertor >> val; + if (convertor.fail() == true) { + val = 0; + } + return val; } const int INTTypeHelper::dexInt(const string str) { int val = 0; - sscanf(str.c_str(), "%x", &val); + stringstream convertor(str); + + convertor >> hex >> val; + if (convertor.fail() == true) { + val = 0; + } return val; } diff --git a/xmlresource/xml_parser_utils.cpp b/xmlresource/xml_parser_utils.cpp index 3d40a0b..5ec17c0 100644 --- a/xmlresource/xml_parser_utils.cpp +++ b/xmlresource/xml_parser_utils.cpp @@ -18,6 +18,9 @@ #include "xml_parser_utils.h" #include #include +#include + +using namespace std; int get_content_int(const xmlNodePtr cur_node) { @@ -96,7 +99,12 @@ dex_string_to_int(const char* str) { assert(str != NULL); int val = -1; - sscanf(str, "%x", &val); + stringstream convertor(str); + + convertor >> hex >> val; + if (convertor.fail() == true) { + val = -1; + } return val; } -- 2.7.4