Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "Mark" <mark_cruzNOTFORSPAM@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | uninitialised value & valgrind |
| Date | 2012-06-26 12:35 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jscobj$amb$1@speranza.aioe.org> (permalink) |
Hello
I'm working with a legacy code that I link to my application, and run it
under 'valgrind' tool to catch memory leaks, corrupted memory etc. So here
is what it looks like:
#define VLOG_MSG_MAX_DATA_SIZE 1024
struct vlog_msg_header
{
u_int32_t vmh_vr_id;
u_int16_t vmh_msg_type;
module_id_t vmh_mod_id;
u_int32_t vmh_proc_id;
s_int8_t vmh_priority;
u_int32_t vmh_data_len;
};
struct vlog_msg
{
struct vlog_msg_header vms_msg_hdr;
char vms_msg_data[VLOG_MSG_MAX_DATA_SIZE+1];
};
int vlog_client_send_message (struct vlog_msg *msg)
{
...
write (sock, (void *) msg, msg_len); /* line 103. */
}
int vlog_client_send_ctrl_msg ()
{
struct vlog_msg_header header;
/* initialise 'header' .. */
vlog_client_send_message ((struct vlog_msg *)&header); /* line 41*/
return RES_OK;
}
Valgrind reports:
==1634== Syscall param write(buf) points to uninitialised byte(s)
==1634== at 0x6D2D22E: __write_nocancel (syscall-template.S:82)
==1634== by 0x8116E68: vlog_client_send_message (vlog_client.c:103)
==1634== by 0x8116EBF: vlog_client_send_ctrl_msg (vlog_client.c:41)
==1634== by 0x8116EE6: vlog_client_connect_cb (vlog_client.c:211)
==1634== by 0x80C9A3F: message_client_start (message.c:597)
==1634== by 0x8116BA8: vlog_client_start (vlog_client.c:294)
==1634== by 0x8116DA1: vlog_client_create (vlog_client.c:255)
==1634== by 0x80C8FF1: openzlog (log.c:116)
==1634== by 0x805AF95: ldp_start (ldp_main.c:85)
==1634== by 0x8049F39: main (ldp.c:167)
==1634== Address 0xfe541aee is on thread 1's stack
==1634== Uninitialised value was created by a stack allocation
==1634== at 0x8116E7F: vlog_client_send_ctrl_msg (vlog_client.c:32)
I assume valgrind complains because vlog_client_send_message() expects to
get object of type 'struct vlog_msg', but instead we pass 'struct
vlog_msg_header' and everything beyond it (what is supposed to be occupied
by 'char vms_msg_data[VLOG_MSG_MAX_DATA_SIZE+1]' is undefined. Does it sound
correct ?
My question is -- is it valid to typecast this way or it involves undefined
behaviours?
Thanks.
Mark
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
uninitialised value & valgrind "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2012-06-26 12:35 -0400
Re: uninitialised value & valgrind James Kuyper <jameskuyper@verizon.net> - 2012-06-26 13:53 -0400
Re: uninitialised value & valgrind "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2012-06-26 14:07 -0400
Re: uninitialised value & valgrind James Kuyper <jameskuyper@verizon.net> - 2012-06-26 15:42 -0400
Re: uninitialised value & valgrind Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-06-27 02:09 +0200
csiph-web