Fix Svace/Coverity defects 90/274490/7 accepted/tizen/unified/20220501.223711 submit/tizen/20220429.103739
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 29 Apr 2022 05:40:47 +0000 (14:40 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 29 Apr 2022 07:07:24 +0000 (16:07 +0900)
- SIGNED_TO_BIGGER_UNSIGNED
- NO_CAST.INTEGER_OVERFLOW
- CHECKED_RETURN

[Version] 0.1.52
[Issue Type] Svace/Coverity

Change-Id: Ie13f93f372af0c74a2186cb1a0c2a6bf10043623

packaging/capi-media-tool.spec
src/media_packet.c
test/media_packet_test.c

index 95f802662f5c7bb8a1e172df3fce21978d358cca..06f3c6c7bba4ac10394566a1e4d6f003a9d02dcd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-tool
 Summary:    A Core API media tool library in Tizen Native API
-Version:    0.1.51
+Version:    0.1.52
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 40c91a2c47b166bb64cfc7f34da0e3c1f93ba5ed..7e2be690123be129ac7d37c2d6b8b1d6a1e74056 100644 (file)
@@ -518,13 +518,13 @@ static int __pkt_dealloc_buffer(media_packet_s *handle)
 static size_t __pkt_calculate_video_buffer_size(media_packet_s *pkt)
 {
        int stride = 0;
-       int width = 0;
-       int height = 0;
+       unsigned int width = 0;
+       unsigned int height = 0;
        size_t buffersize = 0;
 
        if (MEDIA_FORMAT_IS_VIDEO(pkt->format)) {
-               width = pkt->format->detail.video.width;
-               height = pkt->format->detail.video.height;
+               width = (unsigned int)pkt->format->detail.video.width;
+               height = (unsigned int)pkt->format->detail.video.height;
        }
 
        /* TODO : need to check type mapping again with mm_transform */
@@ -533,7 +533,7 @@ static size_t __pkt_calculate_video_buffer_size(media_packet_s *pkt)
        case MEDIA_FORMAT_I420:
        case MEDIA_FORMAT_YV12:
                stride = _ROUND_UP_16(width);
-               buffersize = (stride + (_ROUND_UP_16(width) / 2)) * height;
+               buffersize = (size_t)((stride + (_ROUND_UP_16(width) / 2)) * height);
                break;
        case MEDIA_FORMAT_YUYV:
        case MEDIA_FORMAT_UYVY:
@@ -541,17 +541,17 @@ static size_t __pkt_calculate_video_buffer_size(media_packet_s *pkt)
        case MEDIA_FORMAT_RGB565:
        case MEDIA_FORMAT_422P:
                stride = _ROUND_UP_16(width * 2);
-               buffersize = stride * height;
+               buffersize = (size_t)(stride * height);
                break;
        case MEDIA_FORMAT_RGB888:
                stride = _ROUND_UP_16(width * 3);
-               buffersize = stride * height;
+               buffersize = (size_t)(stride * height);
                break;
        case MEDIA_FORMAT_ARGB:
        case MEDIA_FORMAT_RGBA:
        case MEDIA_FORMAT_BGRA:
                stride = width * 4;
-               buffersize = stride * height;
+               buffersize = (size_t)(stride * height);
                break;
        case MEDIA_FORMAT_NV12:
        case MEDIA_FORMAT_NV12T:
@@ -574,7 +574,7 @@ static size_t __pkt_calculate_video_buffer_size(media_packet_s *pkt)
        case MEDIA_FORMAT_XVID:
        case MEDIA_FORMAT_AV1:
                stride = _ROUND_UP_16(width);
-               buffersize = (stride + (_ROUND_UP_16(width) / 2)) * height;
+               buffersize = (size_t)((stride + (_ROUND_UP_16(width) / 2)) * height);
                break;
        default:
                LOGE("Not supported format");   //LCOV_EXCL_LINE
index f3b8031462c015b4ea01973e5f834736cde101ac..cfca7deb321fc1cd8fd6fbc5abfc97d3a98c5bf1 100644 (file)
@@ -1336,11 +1336,20 @@ void display_sub_basic()
 
 gboolean input(GIOChannel *channel)
 {
+       GIOStatus status;
        gchar buf[MAX_STRING_LEN];
        gsize read;
        GError *error = NULL;
 
-       g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
+       status = g_io_channel_read_chars(channel, buf, sizeof(buf), &read, &error);
+       if (status != G_IO_STATUS_NORMAL) {
+               g_printerr("failed to g_io_channel_read_chars(), status[%d][%s]",
+                               status, error ? error->message : "(null)");
+               if (error)
+                       g_error_free(error);
+               return TRUE;
+       }
+
        buf[read] = '\0';
        g_strstrip(buf);
        interpret(buf);