Skip to content

Commit

Permalink
Refactor shm_str_resize() into shm_str_extend()
Browse files Browse the repository at this point in the history
This hints better at what the function actually does (i.e. it will not
shrink your buffers)
  • Loading branch information
liviuchircu committed Jan 11, 2018
1 parent 7d05907 commit cb8bc5d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/fraud_detection/fraud_detection.c
Expand Up @@ -346,7 +346,7 @@ static int check_fraud(struct sip_msg *msg, char *_user, char *_number, char *_p
++se->stats.seq_calls;
}
else {
if (shm_str_resize(&se->stats.last_called_prefix, matched_len) != 0) {
if (shm_str_extend(&se->stats.last_called_prefix, matched_len) != 0) {
LM_ERR("oom\n");
return rc_error;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/kv_store.c
Expand Up @@ -74,7 +74,7 @@ int_str_t *kv_put(map_t _store, const str* _key, const int_str_t* _val)
new_val->is_str = 1;
}

if (shm_str_resize(&new_val->s, _val->s.len + 1) != 0) {
if (shm_str_extend(&new_val->s, _val->s.len + 1) != 0) {
LM_ERR("oom\n");
return NULL;
}
Expand Down
8 changes: 6 additions & 2 deletions ut.h
Expand Up @@ -677,8 +677,12 @@ static inline char *shm_strdup(const char *str)
return rval;
}

/* Extend the given buffer only if needed */
static inline int shm_str_resize(str *in, int size)
/*
* Ensure the given (str *) points to an SHM buffer of at least "size" bytes
*
* Return: 0 on success, -1 on failure
*/
static inline int shm_str_extend(str *in, int size)
{
char *p;

Expand Down

0 comments on commit cb8bc5d

Please sign in to comment.