Add assertion after malloc in the message class 21/306521/2 accepted/tizen_unified_toolchain accepted/tizen/unified/20240306.094026 accepted/tizen/unified/toolchain/20240311.065615 accepted/tizen/unified/x/20240307.010706
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 22 Feb 2024 10:20:40 +0000 (19:20 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 22 Feb 2024 11:16:23 +0000 (20:16 +0900)
Since message class is written under presumtion that malloc will never
return NULL(there is no NULL-checking code), it is better to insert an
assertion after malloc was called.

This solves bug reported by SVACE with WGID:
696636 695764 696678 696677 696676 696638 696635 696654 696653 696652
696651 696650 696649 696648 696647 696646 696643 696641 696640 696639

Change-Id: I258a1d141a18283d9b5a5108e82f505ba610c86d
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/shared/message.cpp

index 5f12d23..f8ab962 100644 (file)
@@ -22,6 +22,8 @@
 #include <sensor_log.h>
 #include <atomic>
 
+#include <assert.h>
+
 using namespace ipc;
 
 #define UNDEFINED_TYPE -2
@@ -33,6 +35,7 @@ message::message(size_t capacity)
        , m_capacity(capacity)
        , m_msg((char *)malloc(sizeof(char) * capacity))
 {
+       assert(m_msg != NULL);
        m_header.id = sequence++;
        m_header.type = UNDEFINED_TYPE;
        m_header.length = m_size;
@@ -55,6 +58,7 @@ message::message(const message &msg)
        , m_capacity(msg.m_capacity)
        , m_msg((char *)malloc(sizeof(char) * msg.m_capacity))
 {
+       assert(m_msg != NULL);
        ::memcpy(&m_header, &msg.m_header, sizeof(message_header));
        ::memcpy(m_msg, msg.m_msg, msg.m_size);
 }