Fix bug in dlog message format
[apps/native/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-util.c
index 96ffea1..5b80486 100644 (file)
@@ -3,7 +3,7 @@
 *
 * Copyright 2012  Samsung Electronics Co., Ltd
 
-* Licensed under the Flora License, Version 1.0 (the "License");
+* Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 
@@ -61,7 +61,7 @@ char *wfd_app_trim_path(const char *filewithpath)
        const char *space = "                                        ";
        int len = strlen(filewithpath);
 
-       if (len > 20) {
+       if (len >= 20) {
                strptr = (char *) filewithpath + (len - 20);
                start = 0;
        } else if (len < 20) {
@@ -70,7 +70,8 @@ char *wfd_app_trim_path(const char *filewithpath)
        }
 
        strncpy((char *) filename, space, strlen(space));
-       strncpy((char *) filename + start, strptr, 50);
+       if(strptr)
+               strncpy((char *) filename + start, strptr, 50);
 
        return (char *) filename;
 #endif
@@ -112,13 +113,18 @@ static void _move_data_to_app_control(const char *key, const int type,
        size_t size = 0;
 
 
-       WFD_RET_IF(data == NULL || key == NULL || type == 0, "Invialid parameter!");
+       WFD_RET_IF(data == NULL || key == NULL || type == 0, "Invialid parameter!");
 
        app_control_h control = data;
 
        if (type == BUNDLE_TYPE_STR) {
                bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
                buff = malloc(sizeof(char) * size + 1);
+               if (buff == NULL) {
+                       WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory");
+                       __WFD_APP_FUNC_EXIT__;
+                       return;
+               }
                snprintf(buff, size + 1, "%s", ((char*) ptr));
                WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %d", key, buff, size);
 
@@ -127,6 +133,11 @@ static void _move_data_to_app_control(const char *key, const int type,
        } else if (type == BUNDLE_TYPE_BYTE) {
                bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
                buff = malloc(sizeof(char) * size + 1);
+               if (buff == NULL) {
+                       WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory");
+                       __WFD_APP_FUNC_EXIT__;
+                       return;
+               }
                snprintf(buff, size + 1, "%s", ((char*) ptr));
                WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %d", key, buff, size);