FailMsg and LocMsg contain char* fields which are not const. Assigning
the passed const char* to a FailMsg or LocMsg violates the const.
To avoid this, a copy of the data is made using strdup. Yes, the
extra copy is functionally unnecessary, but to honor the const
it must be done.
The alternative is to make the char* fields in FailMsg and LocMsg
const. This will not work, however, as those fields are sometimes
assigned malloc'ed data in the code and free'd. You cannot pass
a const pointer to free without a warning.
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@1064
64e312b2-a51f-0410-8e61-
82d0ca0eb02a
void send_failure_info(const char *msg)
{
FailMsg fmsg;
- fmsg.msg = (char *) msg;
+ fmsg.msg = strdup(msg);
ppack(get_pipe(), CK_MSG_FAIL, (CheckMsg *) &fmsg);
+ free(fmsg.msg);
}
void send_duration_info(int duration)
void send_loc_info(const char * file, int line)
{
LocMsg lmsg;
- lmsg.file = (char *) file;
+ lmsg.file = strdup(file);
lmsg.line = line;
ppack(get_pipe(), CK_MSG_LOC, (CheckMsg *) &lmsg);
+ free(lmsg.file);
}
void send_ctx_info(enum ck_result_ctx ctx)