Fix minor issues 78/255578/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Mar 2021 08:41:13 +0000 (17:41 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Mar 2021 08:41:13 +0000 (17:41 +0900)
- Fix coding rule.
- Fix static analysis issues.

Change-Id: I391fbac9f7ec865fc06cbab7c204fa619c00e038
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/client/pkginfo_client.cc
src/common/socket/client_socket.cc
src/server/pkg_request.cc

index b314e77..4cedf8c 100644 (file)
@@ -89,7 +89,7 @@ PkgInfoClient::GetResultParcel() {
     return nullptr;
   }
   int len = 0;
-  if (socket_->ReceiveData(&len, sizeof(len)) != 0) {
+  if (socket_->ReceiveData(&len, sizeof(len)) != 0 || len <= 0) {
     LOGE("Fail to receive data");
     socket_->Disconnect();
     return nullptr;
index 51c0cf9..5558644 100644 (file)
@@ -43,8 +43,10 @@ void ClientSocket::SetTimeout(int timeout_msec) {
   struct timeval timeout = {
       .tv_sec = static_cast<time_t>(timeout_msec / 1000),
       .tv_usec = static_cast<suseconds_t>((timeout_msec % 1000) * 1000)};
-  int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
-  if (ret < 0) LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+  int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout,
+      sizeof(timeout));
+  if (ret < 0)
+    LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
 }
 
 bool ClientSocket::Connect() {
@@ -73,13 +75,22 @@ bool ClientSocket::Connect() {
 
 int ClientSocket::TryConnection() {
   int flags = fcntl(fd_, F_GETFL, 0);
-  fcntl(fd_, F_SETFL, flags | O_NONBLOCK);
+  if (fcntl(fd_, F_SETFL, flags | O_NONBLOCK) != 0) {
+    LOGE("Failed to set flags(%d) on fd(%d), errno(%d)",
+        flags | O_NONBLOCK, fd_, errno);
+    return -1;
+  }
 
   int ret =
       connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(addr_));
-  fcntl(fd_, F_SETFL, flags);
+  if (fcntl(fd_, F_SETFL, flags) != 0) {
+    LOGE("Failed to set flags(%d) on fd(%d), errno(%d)",
+        flags, fd_, errno);
+    return -1;
+  }
   if (ret < 0) {
-    if (errno != EAGAIN && errno != EINPROGRESS) return -2;
+    if (errno != EAGAIN && errno != EINPROGRESS)
+      return -2;
   } else if (ret == 0) {
     SetOption();
     return 0;
@@ -99,7 +110,8 @@ int ClientSocket::TryConnection() {
   if (FD_ISSET(fd_, &readfds) || FD_ISSET(fd_, &writefds)) {
     int error = 0;
     socklen_t len = sizeof(error);
-    if (getsockopt(fd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0) return -1;
+    if (getsockopt(fd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
+      return -1;
   }
 
   return -1;
index d2f0d30..d57aadf 100644 (file)
@@ -60,7 +60,7 @@ bool PkgRequest::ReceiveData() {
     request_type_ = pkgmgr_common::REQ_TYPE_NONE;
     return false;
   }
-  if (data_size_ < 0) {
+  if (data_size_ <= 0) {
     LOGE("Invalid data");
     request_type_ = pkgmgr_common::REQ_TYPE_NONE;
     return false;