From cfc0d5c11ab645bbf64e3fe73380c7de68f2f2d7 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Wed, 6 Jul 2022 10:52:52 +0900 Subject: [PATCH] [Util] macro to check string Add macro to check valid string. Signed-off-by: Jaeyun --- src/libnnstreamer-edge/nnstreamer-edge-common.c | 6 +++--- src/libnnstreamer-edge/nnstreamer-edge-common.h | 2 ++ src/libnnstreamer-edge/nnstreamer-edge-internal.c | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-common.c b/src/libnnstreamer-edge/nnstreamer-edge-common.c index e4a721f..a58a6bd 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-common.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-common.c @@ -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; } diff --git a/src/libnnstreamer-edge/nnstreamer-edge-common.h b/src/libnnstreamer-edge/nnstreamer-edge-common.h index 8eebda4..ab6d36e 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-common.h +++ b/src/libnnstreamer-edge/nnstreamer-edge-common.h @@ -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) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.c b/src/libnnstreamer-edge/nnstreamer-edge-internal.c index 72b3705..8287584 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.c @@ -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; } -- 2.34.1