[Util] macro to check string accepted/tizen/unified/20220707.133435 submit/tizen/20220706.100329
authorJaeyun <jy1210.jung@samsung.com>
Wed, 6 Jul 2022 01:52:52 +0000 (10:52 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 6 Jul 2022 08:14:08 +0000 (17:14 +0900)
Add macro to check valid string.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
src/libnnstreamer-edge/nnstreamer-edge-common.c
src/libnnstreamer-edge/nnstreamer-edge-common.h
src/libnnstreamer-edge/nnstreamer-edge-internal.c

index e4a721fe7e3e0aac9a1086ce1bdd3c554f06bd7d..a58a6bd921506d5ac1f2f6a498194525afef3b8d 100644 (file)
@@ -491,12 +491,12 @@ nns_edge_data_set_info (nns_edge_data_h data_h, const char *key,
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!key || *key == '\0') {
+  if (!STR_IS_VALID (key)) {
     nns_edge_loge ("Invalid param, given key is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!value || *value == '\0') {
+  if (!STR_IS_VALID (value)) {
     nns_edge_loge ("Invalid param, given value is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
@@ -523,7 +523,7 @@ nns_edge_data_get_info (nns_edge_data_h data_h, const char *key, char **value)
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!key || *key == '\0') {
+  if (!STR_IS_VALID (key)) {
     nns_edge_loge ("Invalid param, given key is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
index 8eebda4e66d74bf0cbf982257a5958eafe1ea39a..ab6d36e43082fb8d90f056086dc019aae032a849 100644 (file)
@@ -29,6 +29,8 @@ extern "C" {
 #define UNUSED(expr) do { (void)(expr); } while (0)
 #endif
 
+#define STR_IS_VALID(s) ((s) && (s)[0] != '\0')
+
 #define NNS_EDGE_MAGIC 0xfeedfeed
 #define NNS_EDGE_MAGIC_DEAD 0xdeaddead
 #define NNS_EDGE_MAGIC_IS_VALID(h) ((h) && (h)->magic == NNS_EDGE_MAGIC)
index 72b3705ef30fb5a46a0c63e7044f1b51223a5bc9..8287584ab205f9d531e28527656d3b9301e5c2f7 100644 (file)
@@ -874,7 +874,7 @@ _nns_edge_accept_socket_async_cb (GObject * source, GAsyncResult * result,
   /* Send capability and info to check compatibility. */
   client_id = eh->is_server ? g_get_monotonic_time () : eh->client_id;
 
-  if (!eh->caps_str || *eh->caps_str == '\0') {
+  if (!STR_IS_VALID (eh->caps_str)) {
     nns_edge_loge ("Cannot accept socket, invalid capability.");
     goto error;
   }
@@ -943,12 +943,12 @@ nns_edge_create_handle (const char *id, const char *topic, nns_edge_h * edge_h)
 {
   nns_edge_handle_s *eh;
 
-  if (!id || *id == '\0') {
+  if (!STR_IS_VALID (id)) {
     nns_edge_loge ("Invalid param, given ID is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!topic || *topic == '\0') {
+  if (!STR_IS_VALID (topic)) {
     nns_edge_loge ("Invalid param, given topic is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
@@ -1148,7 +1148,7 @@ nns_edge_connect (nns_edge_h edge_h, nns_edge_protocol_e protocol,
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!ip || *ip == '\0') {
+  if (!STR_IS_VALID (ip)) {
     nns_edge_loge ("Invalid param, given IP is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
@@ -1402,12 +1402,12 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value)
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!key || *key == '\0') {
+  if (!STR_IS_VALID (key)) {
     nns_edge_loge ("Invalid param, given key is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!value || *value == '\0') {
+  if (!STR_IS_VALID (value)) {
     nns_edge_loge ("Invalid param, given value is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }