From 84c5febb83c52dd7f7286df44a51a78b18ffe00e Mon Sep 17 00:00:00 2001 From: hj kim Date: Fri, 13 Mar 2020 13:15:59 +0900 Subject: [PATCH] check src before doing g_strlcpy and g_strlcat if src is NULL, get " GLib-CRITICAL **: g_strlcpy: assertion 'src != NULL' failed" Change-Id: Ia14aec3378bb7dd45b26b740ae4a8ff53054a092 --- src/include/common/media-svc-util.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h index 28e0580..7129bbf 100755 --- a/src/include/common/media-svc-util.h +++ b/src/include/common/media-svc-util.h @@ -34,12 +34,25 @@ extern "C" { #endif -#define SAFE_FREE(src) { if (src) {free(src); src = NULL; } } -#define STRING_VALID(str) \ - ((str != NULL && strlen(str) > 0) ? true : false) +#define STRING_VALID(str) (str != NULL && strlen(str) > 0) -#define SAFE_STRLCAT(dst, src, n) g_strlcat(dst, src, n); -#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n); +#define SAFE_FREE(src) do { \ + if (src) { \ + free(src); \ + src = NULL; \ + } \ + } while (0) + + +#define SAFE_STRLCAT(dst, src, n) do { \ + if (src) \ + g_strlcat(dst, src, n); \ + } while (0) + +#define SAFE_STRLCPY(dst, src, n) do { \ + if (src) \ + g_strlcpy(dst, src, n); \ + } while (0) /** * Media meta data information -- 2.7.4