Skip to content

Commit

Permalink
Merge branch 'main' into coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Apr 29, 2024
2 parents 1d69e1c + 06ce16c commit b4c5c12
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: coverage check
run: |
min_cov="63.8"
min_cov="64.4"
cov=$(~/.local/bin/gcovr -r . -s | grep lines | awk '{ print $2 }' | sed 's/%//')
echo "Coverage: ${cov}% (min $min_cov%)"
exit $(echo "$cov < $min_cov" | bc -l)
1 change: 0 additions & 1 deletion include/re_dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ typedef void (dbg_print_h)(int level, const char *p, size_t len, void *arg);

void dbg_init(int level, enum dbg_flags flags);
void dbg_close(void);
int dbg_logfile_set(const char *name);
void dbg_handler_set(dbg_print_h *ph, void *arg);
void dbg_printf(int level, const char *fmt, ...);
const char *dbg_level_str(int level);
Expand Down
2 changes: 1 addition & 1 deletion include/re_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ typedef int re_sock_t;
#define HAVE_RE_ARG 1

#define RE_ARG_SIZE(type) \
_Generic((type), \
_Generic((0)?(type):(type), \
bool: sizeof(int), \
char: sizeof(int), \
unsigned char: sizeof(unsigned int), \
Expand Down
44 changes: 2 additions & 42 deletions src/dbg/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ static struct {
enum dbg_flags flags; /**< Debug flags */
dbg_print_h *ph; /**< Optional print handler */
void *arg; /**< Handler argument */
FILE *f; /**< Logfile */
} dbg = {
0,
DBG_INFO,
DBG_ANSI,
NULL,
NULL,
NULL,
};

static once_flag flag = ONCE_FLAG_INIT;
Expand Down Expand Up @@ -82,37 +80,6 @@ void dbg_init(int level, enum dbg_flags flags)
*/
void dbg_close(void)
{
if (dbg.f) {
(void)fclose(dbg.f);
dbg.f = NULL;
}
}


/**
* Set debug logfile
*
* @param name Name of the logfile, NULL to close
*
* @return 0 if success, otherwise errorcode
*/
int dbg_logfile_set(const char *name)
{
int err;

dbg_close();

if (!name)
return 0;

err = fs_fopen(&dbg.f, name, "a+");
if (err)
return err;

(void)re_fprintf(dbg.f, "\n===== Log Started: %H", fmt_gmtime, NULL);
(void)fflush(dbg.f);

return 0;
}


Expand Down Expand Up @@ -180,7 +147,7 @@ static void dbg_vprintf(int level, const char *fmt, va_list ap)
}


/* Formatted output to print handler and/or logfile */
/* Formatted output to print handler */
static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
{
char buf[256];
Expand All @@ -191,10 +158,9 @@ static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
if (level > dbg.level)
goto out;

if (!dbg.ph && !dbg.f)
if (!dbg.ph)
goto out;


len = re_vsnprintf(buf, sizeof(buf), fmt, ap);
if (len <= 0)
goto out;
Expand All @@ -204,12 +170,6 @@ static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
dbg.ph(level, buf, len, dbg.arg);
}

/* Output to file */
if (dbg.f) {
if (fwrite(buf, 1, len, dbg.f) > 0)
(void)fflush(dbg.f);
}

out:
dbg_unlock();
}
Expand Down
5 changes: 3 additions & 2 deletions src/fmt/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,12 @@ 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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtp/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ void rtcp_sess_rx_rtp(struct rtcp_sess *sess, struct rtp_header *hdr,
}

if (!rtp_source_update_seq(mbr->s, hdr->seq)) {
DEBUG_WARNING("rtp_update_seq() returned 0\n");
DEBUG_WARNING("rtp_source_update_seq() returned 0\n");
}

if (sess->srate_rx) {
Expand Down
11 changes: 11 additions & 0 deletions test/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -285,7 +286,17 @@ 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;

/* 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_isset(debug_buf));
}
if (err)
goto out;
Expand Down

0 comments on commit b4c5c12

Please sign in to comment.