Replace sscanf with std::stringstream 07/126407/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 20 Apr 2017 04:37:02 +0000 (13:37 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Sun, 23 Apr 2017 23:17:47 +0000 (08:17 +0900)
Change-Id: Ie916e23fe061cab3a3f0b1963a6fe4d94b5c681a

xmlresource/label_properties_parser.cpp
xmlresource/layout_parser_helper.cpp
xmlresource/xml_parser_utils.cpp

index 8d06a51..815062e 100644 (file)
  */
 
 #include <memory.h>
+#include <sstream>
 #include <libxml/parser.h>
 #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;
index 6d606e8..49b9387 100644 (file)
@@ -18,6 +18,7 @@
 #include "layout_parser_helper.h"
 #include <stdio.h>
 #include <string>
+#include <sstream>
 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;
 }
index 3d40a0b..5ec17c0 100644 (file)
@@ -18,6 +18,9 @@
 #include "xml_parser_utils.h"
 #include <string.h>
 #include <assert.h>
+#include <sstream>
+
+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;
 }