X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Fwrapper.c;h=63f5d8aa49edcaf6ae91f6b254fdaf7c0d706249;hb=15fb8a6128ee4f8b4d7096f13422aebe4afd2fec;hp=68af08474fe6b9748116bc887c8e432e92078ef2;hpb=68c1ab2191d9959fde0bd275a560f7c9cf6df485;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/wrapper.c b/src/rmr/common/src/wrapper.c index 68af084..63f5d8a 100644 --- a/src/rmr/common/src/wrapper.c +++ b/src/rmr/common/src/wrapper.c @@ -32,7 +32,7 @@ #include "../include/rmr.h" -#define ADD_SEP 1 +#define ADD_SEP 1 #define NO_SEP 0 /* @@ -63,8 +63,9 @@ static char* build_sval( char* name, char* val, int add_sep ) { strcat src is freed as a convenience. Max is the max amount that target can accept; we don't bang on if src len is larger than max. Return is the size of src; 0 if the - target was not modified. If target is not modified, then - src is NOT released. + target was not modified. + + Source is ALWAYS freed! */ static int bang_on( char* target, char* src, int max ) { int len; @@ -73,16 +74,26 @@ static int bang_on( char* target, char* src, int max ) { if( src && target ) { len = strlen( src ); if( (rc = len <= max ? len : 0 ) > 0 ) { // if it fits, add it. - strcat( target, src ); - free( src ); + strncat( target, src, len ); } } + if( src ) { + free( src ); + } return rc; } +/* + Frees the string that was allocated and returned using rmr_get_consts() +*/ +extern void rmr_free_consts( char* p) { + free(p); +} + /* Returns a set of json with the constants which are set in the header. + Caller must free the returned string using rmr_free_consts() */ extern char* rmr_get_consts( ) { int remain; // bytes remaining in wbuf @@ -108,6 +119,8 @@ extern char* rmr_get_consts( ) { remain -= bang_on( wbuf, phrase, remain ); phrase = build_ival( "RMRFL_AUTO_ALLOC", RMRFL_AUTO_ALLOC, ADD_SEP ); remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMRFL_MTCALL", RMRFL_MTCALL, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); phrase = build_ival( "RMR_DEF_SIZE", RMR_DEF_SIZE, ADD_SEP ); remain -= bang_on( wbuf, phrase, remain ); @@ -150,6 +163,6 @@ extern char* rmr_get_consts( ) { phrase = build_ival( "RMR_ERR_INITFAILED", RMR_ERR_INITFAILED, NO_SEP ); remain -= bang_on( wbuf, phrase, remain ); - strcat( wbuf, " }" ); + strncat( wbuf, " }", remain ); return strdup( wbuf ); // chop unused space and return }