From 57485595338a4c4fb4b1ffb7a43c6f4d1e6f5cd7 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 29 Mar 2017 11:36:52 +0900 Subject: [PATCH] Check number of buttons described in xml layout file Change-Id: Ic74a18f3549ca20b3a306bc34d5eba357feeb91f --- res/simple_debug.cpp | 60 ++++++++++++++++++++++++++++++------------- xmlresource/layout_parser.cpp | 43 ++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 27 deletions(-) diff --git a/res/simple_debug.cpp b/res/simple_debug.cpp index 92b4f7e..cf35900 100644 --- a/res/simple_debug.cpp +++ b/res/simple_debug.cpp @@ -22,6 +22,7 @@ #include #include #include +#include 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 diff --git a/xmlresource/layout_parser.cpp b/xmlresource/layout_parser.cpp index 6c11ccf..f94a699 100644 --- a/xmlresource/layout_parser.cpp +++ b/xmlresource/layout_parser.cpp @@ -22,6 +22,7 @@ #include #include +#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 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"); -- 2.7.4