From 21702294b225c57e7bf373d8c507c5483e81eb92 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:30:03 +0200 Subject: [PATCH 1/9] test: add usage of rtcp_msg_print() --- test/rtp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/rtp.c b/test/rtp.c index ca67f2d81..823a9dd73 100644 --- a/test/rtp.c +++ b/test/rtp.c @@ -285,6 +285,11 @@ int test_rtcp_encode(void) while (mbuf_get_left(mb) >= 4 && !err) { struct rtcp_msg *msg = NULL; err = rtcp_decode(&msg, mb); + if (err) + break; + + DEBUG_NOTICE("%H\n", rtcp_msg_print, msg); + msg = mem_deref(msg); } if (err) From 9233c4a110839f2dafbd2fc2816f6b586070f186 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:53:31 +0200 Subject: [PATCH 2/9] add casting of bitfield values to avoid crash --- src/fmt/print.c | 4 ++-- src/rtp/rtcp.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fmt/print.c b/src/fmt/print.c index a02fb858b..7a13cccda 100644 --- a/src/fmt/print.c +++ b/src/fmt/print.c @@ -494,11 +494,11 @@ static int vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg, out: #ifndef RELEASE if (err == ENODATA) { - DEBUG_WARNING("Format: \"%b<-- NO ARG\n", fmt, p - fmt + 1); + re_fprintf(stderr, "Format: \"%b<-- NO ARG\n", fmt, p - fmt + 1); re_assert(0 && "RE_VA_ARG: no more arguments"); } if (err == EOVERFLOW) { - DEBUG_WARNING("Format: \"%b<-- SIZE ERROR\n", fmt, + re_fprintf(stderr, "Format: \"%b<-- SIZE ERROR\n", fmt, p - fmt + 1); re_assert(0 && "RE_VA_ARG: arg is not compatible"); } diff --git a/src/rtp/rtcp.c b/src/rtp/rtcp.c index 51142a726..7622b2926 100644 --- a/src/rtp/rtcp.c +++ b/src/rtp/rtcp.c @@ -202,10 +202,10 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) if (!msg) return 0; - err = re_hprintf(pf, "%8s pad=%d count=%-2d pt=%-3d len=%u ", + err = re_hprintf(pf, "%8s pad=%u count=%-2u pt=%-3u len=%u ", rtcp_type_name((enum rtcp_type)msg->hdr.pt), - msg->hdr.p, - msg->hdr.count, msg->hdr.pt, msg->hdr.length); + (unsigned)msg->hdr.p, + (unsigned)msg->hdr.count, (unsigned)msg->hdr.pt, msg->hdr.length); if (err) return err; @@ -222,7 +222,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) for (i=0; ihdr.count && !err; i++) { const struct rtcp_rr *rr = &msg->r.sr.rrv[i]; err = re_hprintf(pf, " {%08x %u %d %u %u %u %u}", - rr->ssrc, rr->fraction, rr->lost, + rr->ssrc, rr->fraction, (int)rr->lost, rr->last_seq, rr->jitter, rr->lsr, rr->dlsr); } @@ -233,7 +233,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) for (i=0; ihdr.count && !err; i++) { const struct rtcp_rr *rr = &msg->r.rr.rrv[i]; err = re_hprintf(pf, " {0x%08x %u %d %u %u %u %u}", - rr->ssrc, rr->fraction, rr->lost, + rr->ssrc, rr->fraction, (int)rr->lost, rr->last_seq, rr->jitter, rr->lsr, rr->dlsr); } @@ -258,7 +258,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) break; case RTCP_BYE: - err = re_hprintf(pf, "%u srcs:", msg->hdr.count); + err = re_hprintf(pf, "%u srcs:", (unsigned)msg->hdr.count); for (i=0; ihdr.count && !err; i++) { err = re_hprintf(pf, " %08x", msg->r.bye.srcv[i]); From 728b3d89a82aeac83ac5cbb9d8e15476a820e33b Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:55:35 +0200 Subject: [PATCH 3/9] lint --- src/fmt/print.c | 3 ++- src/rtp/rtcp.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fmt/print.c b/src/fmt/print.c index 7a13cccda..040dd3aac 100644 --- a/src/fmt/print.c +++ b/src/fmt/print.c @@ -494,7 +494,8 @@ static int vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg, out: #ifndef RELEASE if (err == ENODATA) { - re_fprintf(stderr, "Format: \"%b<-- NO ARG\n", fmt, p - fmt + 1); + re_fprintf(stderr, "Format: \"%b<-- NO ARG\n", + fmt, p - fmt + 1); re_assert(0 && "RE_VA_ARG: no more arguments"); } if (err == EOVERFLOW) { diff --git a/src/rtp/rtcp.c b/src/rtp/rtcp.c index 7622b2926..fdf0c7ca7 100644 --- a/src/rtp/rtcp.c +++ b/src/rtp/rtcp.c @@ -205,7 +205,8 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) err = re_hprintf(pf, "%8s pad=%u count=%-2u pt=%-3u len=%u ", rtcp_type_name((enum rtcp_type)msg->hdr.pt), (unsigned)msg->hdr.p, - (unsigned)msg->hdr.count, (unsigned)msg->hdr.pt, msg->hdr.length); + (unsigned)msg->hdr.count, + (unsigned)msg->hdr.pt, msg->hdr.length); if (err) return err; From 47ae38f16d380c41c9654bb240faf660702f74d6 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:33:02 +0200 Subject: [PATCH 4/9] sync with main --- src/rtp/rtcp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rtp/rtcp.c b/src/rtp/rtcp.c index fdf0c7ca7..f3ad594f6 100644 --- a/src/rtp/rtcp.c +++ b/src/rtp/rtcp.c @@ -202,11 +202,11 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) if (!msg) return 0; - err = re_hprintf(pf, "%8s pad=%u count=%-2u pt=%-3u len=%u ", + err = re_hprintf(pf, "%8s pad=%d count=%-2d pt=%-3d len=%u ", rtcp_type_name((enum rtcp_type)msg->hdr.pt), - (unsigned)msg->hdr.p, - (unsigned)msg->hdr.count, - (unsigned)msg->hdr.pt, msg->hdr.length); + msg->hdr.p, + msg->hdr.count, + msg->hdr.pt, msg->hdr.length); if (err) return err; @@ -223,7 +223,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) for (i=0; ihdr.count && !err; i++) { const struct rtcp_rr *rr = &msg->r.sr.rrv[i]; err = re_hprintf(pf, " {%08x %u %d %u %u %u %u}", - rr->ssrc, rr->fraction, (int)rr->lost, + rr->ssrc, rr->fraction, rr->lost, rr->last_seq, rr->jitter, rr->lsr, rr->dlsr); } @@ -234,7 +234,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) for (i=0; ihdr.count && !err; i++) { const struct rtcp_rr *rr = &msg->r.rr.rrv[i]; err = re_hprintf(pf, " {0x%08x %u %d %u %u %u %u}", - rr->ssrc, rr->fraction, (int)rr->lost, + rr->ssrc, rr->fraction, rr->lost, rr->last_seq, rr->jitter, rr->lsr, rr->dlsr); } @@ -259,7 +259,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) break; case RTCP_BYE: - err = re_hprintf(pf, "%u srcs:", (unsigned)msg->hdr.count); + err = re_hprintf(pf, "%u srcs:", msg->hdr.count); for (i=0; ihdr.count && !err; i++) { err = re_hprintf(pf, " %08x", msg->r.bye.srcv[i]); From 6b8c2fbe454e5dd0152e869e1fe029ef8f101d6a Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:33:49 +0200 Subject: [PATCH 5/9] sync --- src/rtp/rtcp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rtp/rtcp.c b/src/rtp/rtcp.c index f3ad594f6..51142a726 100644 --- a/src/rtp/rtcp.c +++ b/src/rtp/rtcp.c @@ -205,8 +205,7 @@ int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg) err = re_hprintf(pf, "%8s pad=%d count=%-2d pt=%-3d len=%u ", rtcp_type_name((enum rtcp_type)msg->hdr.pt), msg->hdr.p, - msg->hdr.count, - msg->hdr.pt, msg->hdr.length); + msg->hdr.count, msg->hdr.pt, msg->hdr.length); if (err) return err; From 061d6d93e1a62ced2a58148617717a7b764b20d1 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:50:13 +0200 Subject: [PATCH 6/9] sync --- src/fmt/print.c | 6 +++--- test/rtp.c | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fmt/print.c b/src/fmt/print.c index 040dd3aac..142d7c590 100644 --- a/src/fmt/print.c +++ b/src/fmt/print.c @@ -494,12 +494,12 @@ static int vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg, out: #ifndef RELEASE if (err == ENODATA) { - re_fprintf(stderr, "Format: \"%b<-- NO ARG\n", - fmt, p - fmt + 1); + DEBUG_WARNING("Format: \"%b<-- NO ARG\n", + fmt, p - fmt + 1); re_assert(0 && "RE_VA_ARG: no more arguments"); } if (err == EOVERFLOW) { - re_fprintf(stderr, "Format: \"%b<-- SIZE ERROR\n", fmt, + DEBUG_WARNING("Format: \"%b<-- SIZE ERROR\n", fmt, p - fmt + 1); re_assert(0 && "RE_VA_ARG: arg is not compatible"); } diff --git a/test/rtp.c b/test/rtp.c index 823a9dd73..bc4fe33b3 100644 --- a/test/rtp.c +++ b/test/rtp.c @@ -243,6 +243,7 @@ int test_rtcp_encode(void) struct mbuf *mb; const size_t sz = sizeof(rtcp_msg) - 1; const uint32_t srcv[2] = {0x12345678, 0x00abcdef}; + char debug_buf[512]; int err = 0; mb = mbuf_alloc(512); @@ -288,9 +289,14 @@ int test_rtcp_encode(void) if (err) break; - DEBUG_NOTICE("%H\n", rtcp_msg_print, msg); + /* Check that debug print works */ + debug_buf[0] = '\0'; + re_snprintf(debug_buf, sizeof(debug_buf), + "%H", rtcp_msg_print, msg); msg = mem_deref(msg); + + ASSERT_TRUE(str_len(debug_buf) > 0); } if (err) goto out; From 39bd5e8c7b6deef7ff809b03ca79dfbcc0bddd0e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:50:36 +0200 Subject: [PATCH 7/9] sync --- src/fmt/print.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fmt/print.c b/src/fmt/print.c index 142d7c590..a02fb858b 100644 --- a/src/fmt/print.c +++ b/src/fmt/print.c @@ -494,8 +494,7 @@ static int vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg, out: #ifndef RELEASE if (err == ENODATA) { - DEBUG_WARNING("Format: \"%b<-- NO ARG\n", - fmt, p - fmt + 1); + DEBUG_WARNING("Format: \"%b<-- NO ARG\n", fmt, p - fmt + 1); re_assert(0 && "RE_VA_ARG: no more arguments"); } if (err == EOVERFLOW) { From 100987e6aafaf4672c2d43c4f8755ba79ebff58e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:51:41 +0200 Subject: [PATCH 8/9] sync --- test/rtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rtp.c b/test/rtp.c index bc4fe33b3..436ce35f5 100644 --- a/test/rtp.c +++ b/test/rtp.c @@ -296,7 +296,7 @@ int test_rtcp_encode(void) msg = mem_deref(msg); - ASSERT_TRUE(str_len(debug_buf) > 0); + ASSERT_TRUE(str_isset(debug_buf) > 0); } if (err) goto out; From fa84e6b561250b5cbd2f90a49c53baf4706d08b4 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:55:57 +0200 Subject: [PATCH 9/9] fix str_isset --- test/rtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rtp.c b/test/rtp.c index 436ce35f5..3ed53dd6d 100644 --- a/test/rtp.c +++ b/test/rtp.c @@ -296,7 +296,7 @@ int test_rtcp_encode(void) msg = mem_deref(msg); - ASSERT_TRUE(str_isset(debug_buf) > 0); + ASSERT_TRUE(str_isset(debug_buf)); } if (err) goto out;