[Linux-ha-dev] heartbeat per-link status and nice failback
Tue, 28 Mar 2000 06:59:22 -0700
Michael Moerz wrote:
> On Mon, 27 Mar 2000, Alan Robertson wrote:
> > You're not appending a (char*) to the string, so you shouldn't use
> > sizeof(char*). Perhaps you meant sizeof(char) or 2*sizeof(char)? I
> > forget if the stringlen field includes the terminating NULL or not.
> I think that strlen doesn't count NULL - values, so you have to add it
> yourself if you're calculating the memroy consumption.
> kind regards,
> Michael Moerz Systemengineer
> CUBIT IT-Solutions
The line in question was:
buf = ha_malloc(m->stringlen +
((strlen(iface) + sizeof(IFACE)) * sizeof(char *)));
But, the field "m->stringlen" already includes space for a NULL byte. I
went back and reread the code. So, Marcelo didn't need to leave room
for an additional one. This field is initialized in function
ha_msg_new() in this way:
ret->stringlen = sizeof(MSG_START)+sizeof(MSG_END)-1;
So, it leaves room for two strings minus the room for one of the two
bytes associated with the two constants. Unlike strlen, sizeof *does*
count the NULL byte. Perhaps I should have named the field stringspace
instead of stringlen. To further attest to my intentions, when I copy a
message buffer to a string in function msg2string(), I do this:
buf = ha_malloc(m->stringlen);
Fortunately, stringlen is a private field only used a handful of times
in only one file, so it's pretty easy to see how it's used.
It's GREAT to have someone else carefully looking over these patches!
-- Alan Robertson