From: Jihoon Kim Date: Mon, 17 Jun 2024 06:38:04 +0000 (+0900) Subject: Fix issue detected by static analysis tool X-Git-Tag: accepted/tizen/unified/20240618.195736~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bea0e55e1aa8f95167bcbe160d73819cd9b59ff;p=platform%2Fcore%2Fuifw%2Flibscl-core.git Fix issue detected by static analysis tool The pointer returned by operator new can't be null, but it's compared with null at websocket.cpp:718. Change-Id: I6f4892be9d85d2bce6154a60d3c7f96a923ada4e Signed-off-by: Jihoon Kim --- diff --git a/src/sclcoreui.cpp b/src/sclcoreui.cpp index b6a3492..5f2a793 100644 --- a/src/sclcoreui.cpp +++ b/src/sclcoreui.cpp @@ -43,10 +43,13 @@ sclboolean CSCLCoreUI::init() sclboolean ret = FALSE; if (m_impl == NULL) { /* There could be other backend implementations.. */ - m_impl = new CSCLCoreUIEFL; - if (m_impl) { + try { + m_impl = new CSCLCoreUIEFL; ret = m_impl->init(); } + catch (const std::bad_alloc& e) { + LOGE("bad alloc"); + } } return ret; } diff --git a/src/websocket.cpp b/src/websocket.cpp index d84a83f..4e8e4e9 100644 --- a/src/websocket.cpp +++ b/src/websocket.cpp @@ -714,12 +714,14 @@ void CWebHelperAgentWebSocket::on_get_imdata(char **buf, unsigned int *len) ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_GET_IMDATA], values)) { if (values.size() > 0 && buf && len) { int string_length = values.at(0).length(); - (*buf) = new char[string_length + 1]; - if (*buf) { + try { + (*buf) = new char[string_length + 1]; strncpy(*buf, values.at(0).c_str(), string_length); /* Make sure this is a null-terminated string */ *(*buf + string_length) = '\0'; *len = string_length; + } catch (const std::bad_alloc& e) { + LOGE("Bad alloc"); } } } else {