#include "../include/rmr.h"
-#define ADD_SEP 1
+#define ADD_SEP 1
#define NO_SEP 0
/*
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;
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;
}
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 );
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
}