diff --git a/daemon/codec.c b/daemon/codec.c index eacbbbdba..c0a01b790 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -2560,9 +2560,9 @@ void codec_init_payload_type(rtp_payload_type *pt, enum media_type type) { // allocate strings str_init_dup_str(&pt->encoding, &pt->encoding); - str_init_dup(&pt->encoding_with_params, full_encoding); - str_init_dup(&pt->encoding_with_full_params, full_full_encoding); - str_init_dup(&pt->encoding_parameters, params); + pt->encoding_with_params = STR_DUP(full_encoding); + pt->encoding_with_full_params = STR_DUP(full_full_encoding); + pt->encoding_parameters = STR_DUP(params); str_init_dup_str(&pt->format_parameters, &pt->format_parameters); str_init_dup_str(&pt->codec_opts, &pt->codec_opts); diff --git a/daemon/janus.c b/daemon/janus.c index f202a78c7..41aab265a 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -851,7 +851,7 @@ static const char *janus_videoroom_configure(struct websocket_message *wm, struc if (strcmp(jsep_type, "offer")) return "Not an offer"; - g_auto(str) sdp_in = STR_INIT_DUP(jsep_sdp); + g_auto(str) sdp_in = STR_DUP(jsep_sdp); g_auto(sdp_ng_flags) flags; g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT; @@ -956,7 +956,7 @@ static const char *janus_videoroom_start(struct websocket_message *wm, struct ja if (strcmp(jsep_type, "answer")) return "Not an answer"; - g_auto(str) sdp_in = STR_INIT_DUP(jsep_sdp); + g_auto(str) sdp_in = STR_DUP(jsep_sdp); g_auto(sdp_ng_flags) flags; g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT; diff --git a/daemon/main.c b/daemon/main.c index 9a7d3a7d1..8a0ed69b1 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -286,7 +286,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) { // foo=bar ifa = g_slice_alloc0(sizeof(*ifa)); str_init_dup_str(&ifa->name, &name); - str_init_dup(&ifa->alias, s); + ifa->alias = STR_DUP(s); t_queue_push_tail(q, ifa); return 0; } @@ -396,7 +396,7 @@ static int redis_ep_parse(endpoint_t *ep, int *db, char **auth, const char *auth static void parse_cn_payload(str *out, char **in, const char *def, const char *name) { if (!in || !*in) { if (def) - str_init_dup(out, def); + *out = STR_DUP(def); return; } diff --git a/lib/str.h b/lib/str.h index 658ec165a..fbb5be34a 100644 --- a/lib/str.h +++ b/lib/str.h @@ -41,7 +41,7 @@ TYPED_GQUEUE(str, str) #define STR_GS(s) ((str) { (s)->str, (s)->len }) #define STR_LEN(s, len) ((str) { (char *) (s), len }) #define STR_LEN_ASSERT(s, len) ({ assert(sizeof(s) >= len); (str) { (char *) (s), len }; }) -#define STR_INIT_DUP(s) ((str) { g_strdup(s), strlen(s) }) +#define STR_DUP(s) ((str) { g_strdup(s), strlen(s) }) #define STR_CONST_BUF(buf) ((str) { (char *) &buf, sizeof(buf) }) @@ -86,10 +86,6 @@ INLINE int str_cmp_str0(const str *a, const str *b); __attribute__((nonnull(1))) ACCESS(write_only, 1) ACCESS(read_only, 2) -INLINE str *str_init_dup(str *out, const char *s); -__attribute__((nonnull(1))) -ACCESS(write_only, 1) -ACCESS(read_only, 2) INLINE str *str_init_dup_str(str *out, const str *s); INLINE void str_free_dup(str *out); /* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */ @@ -295,11 +291,6 @@ INLINE int str_cmp_str0(const str *a, const str *b) { } return str_cmp_str(a, b); } -INLINE str *str_init_dup(str *out, const char *s) { - out->s = s ? g_strdup(s) : NULL; - out->len = s ? strlen(s) : 0; - return out; -} INLINE str *str_init_dup_str(str *out, const str *s) { if (!s) { *out = STR_NULL; diff --git a/t/test-amr-encode.c b/t/test-amr-encode.c index 8702411b6..d60edf235 100644 --- a/t/test-amr-encode.c +++ b/t/test-amr-encode.c @@ -62,7 +62,7 @@ static void do_test_amr_xx(const char *file, int line, const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = 0 }; str fmtp = STR_NULL; if (fmtp_s) - str_init_dup(&fmtp, fmtp_s); + fmtp = STR_DUP(fmtp_s); encoder_t *e = encoder_new(); assert(e); format_t actual_fmt; @@ -88,7 +88,7 @@ static void do_test_amr_xx(const char *file, int line, assert(expect_s == NULL); encoder_free(e); - free(fmtp.s); + g_free(fmtp.s); av_frame_free(&frame); printf("test ok: %s:%i\n", file, line);