Check for null-termination of strings
[platform/core/base/bundle.git] / src / keyval.c
index e3f906a..d49be0e 100755 (executable)
@@ -39,6 +39,7 @@ keyval_t *keyval_new(keyval_t *kv, const char *key,
                const int type, const void *val, const size_t size)
 {
        int must_free_obj = kv ? 0 : 1;
+       char *str;
 
        if (!kv) {
                kv = calloc(1, sizeof(keyval_t));
@@ -70,8 +71,14 @@ keyval_t *keyval_new(keyval_t *kv, const char *key,
                        keyval_free(kv, must_free_obj);
                        return NULL;
                }
-               if (val)
+               if (val) {
                        memcpy(kv->val, val, size);
+                       if (type == BUNDLE_TYPE_STR) {
+                               str = (char *)kv->val;
+                               if (str[size - 1] != '\0')
+                                       str[size - 1] = '\0';
+                       }
+               }
        }
 
        kv->method = &method;