Fix static analysis issue 76/183076/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 2 Jul 2018 05:47:49 +0000 (14:47 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 2 Jul 2018 06:01:42 +0000 (15:01 +0900)
Issues:
- Dereference before null check

Change-Id: I150571bf9b848cdb603fac2b8d2dd70b30c217f2
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/base/watch_base.c

index 838d46d..60f3124 100755 (executable)
@@ -900,6 +900,28 @@ EXPORT_API int watch_base_init(int argc, char **argv,
        if (!watch_base_check_feature())
                return APP_ERROR_NOT_SUPPORTED;
 
+       if (argc <= 0 || argv == NULL || callback == NULL) {
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+       }
+
+       if (callback->create == NULL) {
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__,
+                               "watch_base_create_cb() callback must be "
+                               "registered");
+       }
+
+       if (__context.state != WATCH_BASE_STATE_NOT_RUNNING) {
+               return watch_base_set_error(APP_ERROR_ALREADY_RUNNING,
+                               __FUNCTION__, NULL);
+       }
+
+       if (app_get_id(&(__context.appid)) != APP_ERROR_NONE) {
+               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT,
+                               __FUNCTION__, "failed to get the appid");
+       }
+
        /* override methods */
        ops.base.create = __on_ui_base_create;
        ops.base.control = __on_ui_base_control;
@@ -937,31 +959,13 @@ EXPORT_API int watch_base_init(int argc, char **argv,
                _E("failed to get launch argv");
        }
 
-       if (argc <= 0 || argv == NULL || callback == NULL)
-               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       if (callback->create == NULL)
-               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__,
-                               "watch_base_create_cb() callback must be "
-                               "registered");
-
-       if (__context.state != WATCH_BASE_STATE_NOT_RUNNING)
-               return watch_base_set_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__,
-                               NULL);
-
-       if (app_get_id(&(__context.appid)) != APP_ERROR_NONE)
-               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               "failed to get the appid");
-
        ret = aul_app_com_create(__context.appid, NULL, __viewer_state_handler,
                        NULL, &__conn_viewer_state);
        if (ret < 0) {
                free(__context.appid);
                __context.appid = NULL;
-               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               "Failed to create app com");
+               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT,
+                               __FUNCTION__, "Failed to create app com");
        }
 
        __context.callback = *callback;