fix build warning
[platform/adaptation/ap_samsung/libomxil-e3250-v4l2.git] / exynos / libv4l2 / exynos_mc.c
index 4025b24..cca6cff 100755 (executable)
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
-#ifndef SLP_PLATFORM /* build env */
+#ifndef TIZEN_FEATURE_E3250 /* build env */
 #include <media.h>
 #else
 #include <linux/media.h>
@@ -49,7 +50,7 @@
 
 //#define LOG_NDEBUG 0
 #define LOG_TAG "libexynosv4l2-mc"
-#ifndef SLP_PLATFORM /* build env */
+#ifndef TIZEN_FEATURE_E3250 /* build env */
 #include <utils/Log.h>
 #else
 #include "Exynos_OSAL_Log.h"
@@ -179,11 +180,11 @@ static int __media_get_devname_sysfs(struct media_entity *entity)
     char *p;
     int ret;
 
-    sprintf(sysname, "/sys/dev/char/%u:%u", entity->info.v4l.major,
+    snprintf(sysname, sizeof(sysname), "/sys/dev/char/%u:%u", entity->info.v4l.major,
         entity->info.v4l.minor);
 
     ret = readlink(sysname, target, sizeof(target));
-    if (ret < 0)
+    if (ret < 0 || ret >= (int)sizeof(target))
         return -errno;
 
     target[ret] = '\0';
@@ -191,21 +192,16 @@ static int __media_get_devname_sysfs(struct media_entity *entity)
     if (p == NULL)
         return -EINVAL;
 
-    sprintf(devname, "/tmp/%s", p + 1);
+    snprintf(devname, sizeof(devname), "/tmp/%s", p + 1);
 
     ret = mknod(devname, 0666 | S_IFCHR, MKDEV(81, entity->info.v4l.minor));
-    strcpy(entity->devname, devname);
+    strncpy(entity->devname, devname, sizeof(devname) - 1);
 
     return 0;
 }
 
 static int __media_get_media_fd(const char *filename, struct media_device *media)
 {
-    ssize_t num;
-    int media_node;
-    char *ptr;
-    char media_buf[6];
-
     ALOGD("%s: %s", __func__, filename);
 
     media->fd = open(filename, O_RDWR, 0);
@@ -231,6 +227,10 @@ static int __media_enum_entities(struct media_device *media)
     for (id = 0, ret = 0; ; id = entity->info.id) {
         size = (media->entities_count + 1) * sizeof(*media->entities);
         media->entities = (struct media_entity*)realloc(media->entities, size);
+        if (media->entities == NULL) {
+            ret = -ENOMEM;
+            break;
+        }
 
         entity = &media->entities[media->entities_count];
         memset(entity, 0, sizeof(*entity));