Add null check about javascript result 08/159008/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 6 Nov 2017 06:49:50 +0000 (15:49 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 6 Nov 2017 09:31:41 +0000 (09:31 +0000)
Change-Id: Ic0cc1f883526f0a62dc01279313aac36b67540bb
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
(cherry picked from commit 8fed984a23cd7b6c43499e27bd30efe7602bffe6)

src/voice_control_webview.cpp

index fe249c76da380e500657698042aa8a5fcbd58b85..6deae5f944f4357d730365425770624ab6d3662c 100755 (executable)
@@ -155,8 +155,8 @@ char* VCWebView::vc_webview_load_script(const char* filename)
        LOGI("==== Load Script ====");
 
        FILE *f = NULL;
-       char js_path[1024] = {'\0',};
-       char buf[256] = {'\0',};
+       char js_path[1024] = {'\0'};
+       char buf[256] = {'\0'};
 
        snprintf(js_path, 1024, "%s/%s", VC_WEBVIEW_JS_PATH, filename);
        LOGD("===path (%s)", js_path);
@@ -174,7 +174,7 @@ char* VCWebView::vc_webview_load_script(const char* filename)
        }
        fseek(f, 0, SEEK_SET);
 
-       char *script = new char [fsize + 1];
+       char *script = new char[fsize + 1];
        long int ret = fread(script, 1, fsize, f);
        if (ret != fsize) {
                LOGE("Couldn't read vc-webview.js file %d, %d", fsize, ret);
@@ -201,9 +201,9 @@ void VCWebView::__vc_webview_init() {
        LOGI("%d ", vc_widget_set_send_current_command_list_cb(g_vc_w, __vc_widget_send_current_command_list_cb, (void*)m_list));
        LOGI("%d ", vc_widget_set_current_language_changed_cb(g_vc_w, __vc_language_changed_cb, NULL));
        #if 0
-       LOGI("%d ",vc_widget_set_request_action_cb(g_vc_w, __vc_request_action_cb, NULL));
-       LOGI("%d ",vc_widget_set_getdata_cb(g_vc_w, __vc_get_client_data_cb, NULL));
-       LOGI("%d ",vc_widget_set_setdata_cb(g_vc_w, __vc_set_client_data_cb, NULL));
+       LOGI("%d ", vc_widget_set_request_action_cb(g_vc_w, __vc_request_action_cb, NULL));
+       LOGI("%d ", vc_widget_set_getdata_cb(g_vc_w, __vc_get_client_data_cb, NULL));
+       LOGI("%d ", vc_widget_set_setdata_cb(g_vc_w, __vc_set_client_data_cb, NULL));
        #endif
        LOGI("%d ", vc_widget_prepare(g_vc_w));
 
@@ -220,7 +220,7 @@ void VCWebView::__vc_webview_init() {
 
        // Load language script
 
-       char filename[64] = {'\0',};
+       char filename[64] = {'\0'};
        char *current = NULL;
        if (0 != vc_widget_get_current_language(g_vc_w, &current)) {
                LOGE("[ERROR] fail to get current langauge");
@@ -572,7 +572,7 @@ void VCWebView::vc_language_changed_cb(const char* previous, const char* current
        if (NULL != m_lang_script)
                delete [] m_lang_script;
 
-       char filename[64] = {'\0',};
+       char filename[64] = {'\0'};
        snprintf(filename, 64, "vc-webview-%s.js", current);
        m_lang_script = vc_webview_load_script(filename);
        if (NULL == m_lang_script) {
@@ -592,7 +592,7 @@ void VCWebView::vc_state_changed_cb(vc_state_e previous, vc_state_e current, voi
                char* lang = NULL;
                vc_widget_get_current_language(g_vc_w, &lang);
                if (NULL != lang) {
-                       char filename[64] = {'\0',};
+                       char filename[64] = {'\0'};
                        snprintf(filename, 64, "vc-webview-%s.js", lang);
                        if (NULL != m_lang_script)
                                delete [] m_lang_script;
@@ -797,8 +797,8 @@ static void __js_get_script_name_cb(Evas_Object *obj, const char *javascript_res
 
        FILE *f = NULL;
        file_name = host_name + path_name + ".js";
-       char js_path[1024] = {'\0',};
-       char buf[256] = {'\0',};
+       char js_path[1024] = {'\0'};
+       char buf[256] = {'\0'};
 
        snprintf(js_path, 1024, "%s/%s", VC_WEBVIEW_CUSTOM_PATH, file_name.c_str());
        LOGD("=== path (%s)", js_path);
@@ -830,7 +830,7 @@ static void __js_get_script_name_cb(Evas_Object *obj, const char *javascript_res
                }
                fseek(f, 0, SEEK_SET);
 
-               char *script = new char [fsize + 1];
+               char *script = new char[fsize + 1];
                long int ret = fread(script, 1, fsize, f);
                if (ret != fsize) {
                        LOGE("Couldn't read vc-webview.js file %d, %d", fsize, ret);
@@ -892,7 +892,12 @@ static void __js_get_conflict_status_cb(Evas_Object *obj, const char *javascript
 
        int *conflict = (int*)data;
 
-       *conflict = atoi(javascript_result);
+       if (NULL != javascript_result) {
+               *conflict = atoi(javascript_result);
+       } else {
+               LOGE("Invalid javascript action");
+               *conflict = -1;
+       }
        g_wait = false;
 }
 
@@ -926,4 +931,4 @@ void VCWebView::vc_remove_tooltip()
        std::string action("REMOVE_TOOLTIP");
        std::string execute = "vc_request_action(\"" + action + "\",\"\");";
        ewk_view_script_execute(m_ewk_view, execute.c_str(), __js_script_execute_result_cb, (void*)"REMOVE_TOOLTIP");
-}
\ No newline at end of file
+}