From: brarcher Date: Sat, 25 Jan 2014 18:18:14 +0000 (+0000) Subject: no longer violate the const part of 'const char *' in send functions. X-Git-Tag: 0.10.0~153 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0de663b17c25092ddd3a616e91d19ffa38952232;p=check no longer violate the const part of 'const char *' in send functions. 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 --- diff --git a/src/check_msg.c b/src/check_msg.c index 318e03b..2a7cb72 100644 --- a/src/check_msg.c +++ b/src/check_msg.c @@ -83,8 +83,9 @@ static FILE * get_pipe(void) 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) @@ -97,9 +98,10 @@ 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)