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 Mar 3, 2024
2 parents e6ea8ab + aefb21e commit 49f7ce6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/re_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ int conf_get(const struct conf *conf, const char *name, struct pl *pl);
int conf_get_str(const struct conf *conf, const char *name, char *str,
size_t size);
int conf_get_u32(const struct conf *conf, const char *name, uint32_t *num);
int conf_get_i32(const struct conf *conf, const char *name, int32_t *num);
int conf_get_bool(const struct conf *conf, const char *name, bool *val);
int conf_apply(const struct conf *conf, const char *name,
conf_h *ch, void *arg);
27 changes: 27 additions & 0 deletions src/conf/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,33 @@ int conf_get_u32(const struct conf *conf, const char *name, uint32_t *num)
}


/**
* Get the numeric signed value of a configuration item
*
* @param conf Configuration object
* @param name Name of config item key
* @param num Returned numeric value of config item, if present
*
* @return 0 if success, otherwise errorcode
*/
int conf_get_i32(const struct conf *conf, const char *name, int32_t *num)
{
struct pl pl;
int err;

if (!conf || !name || !num)
return EINVAL;

err = conf_get(conf, name, &pl);
if (err)
return err;

*num = pl_i32(&pl);

return 0;
}


/**
* Get the boolean value of a configuration item
*
Expand Down
2 changes: 1 addition & 1 deletion src/fmt/text2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void re_text2pcap_trace(const char *name, const char *id, bool in,
if (!pcap_buf)
return;

re_snprintf(pcap_buf, pcap_buf_sz, "%H", re_text2pcap, &pcap);
(void)re_snprintf(pcap_buf, pcap_buf_sz, "%H", re_text2pcap, &pcap);

re_trace_event("pcap", name, 'I', NULL, RE_TRACE_ARG_STRING_COPY,
"pcap", pcap_buf);
Expand Down
18 changes: 13 additions & 5 deletions src/sipsess/listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include <re_sys.h>
#include "sipsess.h"


Expand Down Expand Up @@ -250,11 +251,18 @@ static void target_refresh_handler(struct sipsess_sock *sock,

if ((is_invite && sess->st)
|| (sdp && sess->neg_state == SDP_NEG_LOCAL_OFFER)) {
(void)sip_treplyf(NULL, NULL, sip, msg, false,
500, "Server Internal Error",
"Retry-After: 5\r\n"
"Content-Length: 0\r\n"
"\r\n");
if (!sess->established) {
uint32_t wait = rand_u16() % 11;
(void)sip_treplyf(NULL, NULL, sip, msg, false,
500, "Server Internal Error",
"Retry-After: %u\r\n"
"Content-Length: 0\r\n"
"\r\n", wait);
}
else {
(void)sip_treply(NULL, sip, msg, 491,
"Request Pending");
}
return;
}

Expand Down
19 changes: 14 additions & 5 deletions test/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,40 @@
#include <re.h>
#include "test.h"

#define DEBUG_MODULE "test_conf"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


int test_conf(void)
{
static const char *cfg =
"string_val\trattarei\n"
"u32_val 42\n";
"u32_val 42\n"
"i32_val -23\n";
char str[256];
struct conf *conf;
struct pl pl;
uint32_t u32;
int32_t i32;
int err;

err = conf_alloc_buf(&conf, (uint8_t *)cfg, strlen(cfg));
if (err)
return err;

err = conf_get_str(conf, "string_val", str, sizeof(str));
if (err)
goto out;
TEST_ERR(err);
if (strcmp(str, "rattarei"))
goto badmsg;

err = conf_get_u32(conf, "u32_val", &u32);
if (u32 != 42)
goto badmsg;
TEST_ERR(err);
TEST_EQUALS(42, u32);

err = conf_get_i32(conf, "i32_val", &i32);
TEST_ERR(err);
TEST_EQUALS(-23, i32);

/* Non-existing parameters */
if (0 == conf_get(conf, "rattarei", &pl))
Expand Down

0 comments on commit 49f7ce6

Please sign in to comment.