Check number of buttons described in xml layout file 34/121834/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 29 Mar 2017 02:36:52 +0000 (11:36 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 29 Mar 2017 07:48:49 +0000 (16:48 +0900)
Change-Id: Ic74a18f3549ca20b3a306bc34d5eba357feeb91f

res/simple_debug.cpp
xmlresource/layout_parser.cpp

index 92b4f7e..cf35900 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <dlog.h>
 
 SclLog::SclLog() : m_flog(NULL) {
     char *env = NULL;
@@ -66,9 +67,8 @@ SclLog::log(enum LOG_LEVEL level, char* fmt, ...) {
         "message", "warning", "debug", "error"
     };
 
-    if (m_flog == NULL) {
+    if (level >= MAX_LOG_LEVEL)
         return;
-    }
 
     char str_log[128];
     va_list ap;
@@ -76,22 +76,46 @@ SclLog::log(enum LOG_LEVEL level, char* fmt, ...) {
     vsnprintf(str_log, sizeof(str_log), fmt, ap);
     va_end(ap);
 
-    /*
-     * log current time
-     */
-    time_t now;
-    struct tm timenow;
-
-    time(&now);
-    localtime_r(&now, &timenow);
-
-    char buf[64] = { 0 };
-    asctime_r(&timenow, buf);
-
-    fprintf(m_flog, "[ %s ] %s\n", log_message[level], buf);
-    fprintf(m_flog, "\t%s\n", str_log);
-
-    fflush(m_flog);
+    if (m_flog == NULL) {
+        switch (level) {
+            case WARNING:
+            {
+                LOGW("%s", str_log);
+                break;
+            }
+            case ERROR:
+            {
+                LOGE("%s", str_log);
+                break;
+            }
+            case DEBUG:
+            {
+                LOGD("%s", str_log);
+                break;
+            }
+            default:
+            {
+                LOGI("%s", str_log);
+            }
+        }
+    } else {
+        /*
+         * log current time
+         */
+        time_t now;
+        struct tm timenow;
+
+        time(&now);
+        localtime_r(&now, &timenow);
+
+        char buf[64] = { 0 };
+        asctime_r(&timenow, buf);
+
+        fprintf(m_flog, "[ %s ] %s\n", log_message[level], buf);
+        fprintf(m_flog, "\t%s\n", str_log);
+
+        fflush(m_flog);
+    }
 }
 
 void
index 6c11ccf..f94a699 100644 (file)
@@ -22,6 +22,7 @@
 #include <libxml/parser.h>
 #include <glib.h>
 
+#include "scldebug.h"
 #include "layout_parser.h"
 #include "default_configure_parser.h" /* use data in default_configure.xml */
 #include "xml_parser_utils.h"
@@ -208,8 +209,9 @@ class LayoutParserImpl {
         void free_key_coordinate_table(const PSclLayoutKeyCoordinateTable curTable);
 
         void parsing_layout_row_node(const xmlNodePtr cur_node, const PSclLayout cur_rec_layout,
-            int *row_y, int *sub_layout_height, SclLayoutKeyCoordinatePointer **cur_key);
-        void parsing_key_coordinate_record_node(const xmlNodePtr cur_node, Row* row, SclLayoutKeyCoordinatePointer *cur_key);
+            int *row_y, int *sub_layout_height, SclLayoutKeyCoordinatePointer **cur_key, int layout_no);
+        void parsing_key_coordinate_record_node(const xmlNodePtr cur_node, Row* row,
+            SclLayoutKeyCoordinatePointer *cur_key, int layout_no);
 
         void parsing_label_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
         void parsing_label_image_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
@@ -232,6 +234,7 @@ class LayoutParserImpl {
 
     private:
         int m_layout_size;
+        int m_num_keys[MAX_SCL_LAYOUT];
         SclLayout m_layout_table[MAX_SCL_LAYOUT];
         vector<string> m_file_names;
         SclLayoutKeyCoordinate* m_key_coordinate_pointer_frame[MAX_SCL_LAYOUT][MAX_KEY];
@@ -245,12 +248,17 @@ class LayoutParserImpl {
 
 LayoutParserImpl::LayoutParserImpl() {
     m_layout_size = 0;
+    for (int i = 0; i < MAX_SCL_LAYOUT; ++i) {
+        m_num_keys[i] = 0;
+    }
     memset(m_layout_table, 0x00, sizeof(SclLayout) * MAX_SCL_LAYOUT);
     memset(m_key_coordinate_pointer_frame, 0x00, sizeof(SclLayoutKeyCoordinatePointer) * MAX_SCL_LAYOUT * MAX_KEY);
 }
 
 LayoutParserImpl::~LayoutParserImpl() {
+    m_layout_size = 0;
     for (int i = 0; i < MAX_SCL_LAYOUT; ++i) {
+        m_num_keys[i] = 0;
         for (int j = 0; j < MAX_KEY; ++j) {
             free(m_key_coordinate_pointer_frame[i][j]);
             m_key_coordinate_pointer_frame[i][j] = NULL;
@@ -301,8 +309,10 @@ LayoutParserImpl::load(int layout_id) {
 void LayoutParserImpl::unload() {
     for (int i = 0; i < MAX_SCL_LAYOUT; ++i) {
         for (int j = 0; j < MAX_KEY; ++j) {
-            free(m_key_coordinate_pointer_frame[i][j]);
-            m_key_coordinate_pointer_frame[i][j] = NULL;
+            if (m_key_coordinate_pointer_frame[i][j]) {
+                free(m_key_coordinate_pointer_frame[i][j]);
+                m_key_coordinate_pointer_frame[i][j] = NULL;
+            }
         }
     }
 
@@ -812,11 +822,14 @@ LayoutParserImpl::loading_coordinate_resources(
 
     SclLayoutKeyCoordinatePointer *cur_key = &m_key_coordinate_pointer_frame[layout_no][0];
 
+    if (scl_check_arrindex_unsigned(layout_no, MAX_SCL_LAYOUT)) {
+        m_num_keys[layout_no] = 0;
+    }
     if (*cur_key == NULL) {
         xmlNodePtr child_node = cur_node->xmlChildrenNode;
         while (child_node != NULL) {
             if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_TAG)) {
-                parsing_layout_row_node(child_node, cur_rec_layout, &row_y, &sub_layout_height, &cur_key);
+                parsing_layout_row_node(child_node, cur_rec_layout, &row_y, &sub_layout_height, &cur_key, layout_no);
             }
 
             child_node = child_node->next;
@@ -829,7 +842,8 @@ LayoutParserImpl::parsing_layout_row_node(
         const xmlNodePtr cur_node,
         const PSclLayout cur_rec_layout,
         int *row_y, int *sub_layout_height,
-        SclLayoutKeyCoordinatePointer **cur_key) {
+        SclLayoutKeyCoordinatePointer **cur_key,
+        int layout_no) {
     assert(cur_node != NULL);
 
     Row row = {0};
@@ -870,8 +884,14 @@ LayoutParserImpl::parsing_layout_row_node(
     xmlNodePtr child_node = cur_node->xmlChildrenNode;
     while (child_node != NULL) {
         if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_TAG)) {
-            parsing_key_coordinate_record_node(child_node, &row, *cur_key);
-            (*cur_key)++;
+            if (scl_check_arrindex_unsigned(layout_no, MAX_SCL_LAYOUT) && m_num_keys[layout_no] < MAX_KEY) {
+                parsing_key_coordinate_record_node(child_node, &row, *cur_key, layout_no);
+                (*cur_key)++;
+                m_num_keys[layout_no]++;
+            } else {
+                SCLLOG(SclLog::ERROR, "The number of keys exceeded %d (%d)\n", MAX_KEY, layout_no);
+                return;
+            }
         }
         child_node = child_node->next;
     }
@@ -1329,10 +1349,15 @@ LayoutParserImpl::parsing_auto_popup_keys_record_node(
 void
 LayoutParserImpl::parsing_key_coordinate_record_node(
         const xmlNodePtr cur_node, Row *row,
-        SclLayoutKeyCoordinatePointer *cur_rec_coordinate) {
+        SclLayoutKeyCoordinatePointer *cur_rec_coordinate,
+        int layout_no) {
     assert(cur_node != NULL);
     assert(cur_rec_coordinate != NULL);
 
+    if (scl_check_arrindex_unsigned(layout_no, MAX_SCL_LAYOUT) && m_num_keys[layout_no] >= MAX_KEY) {
+        SCLLOG(SclLog::ERROR, "The number of keys exceeded %d (%d)\n", MAX_KEY, layout_no);
+        return;
+    }
     *cur_rec_coordinate = (SclLayoutKeyCoordinatePointer)malloc(sizeof(SclLayoutKeyCoordinate));
     if (*cur_rec_coordinate == NULL) {
         SCLLOG(SclLog::ERROR, "LayoutParserImpl: memory malloc eror.\n");