Hi!
I can't understand how the constant BLOB_COOKIE is used (c.f. blob.c).
static struct blob_attr *
blob_add(struct blob_buf *buf, struct blob_attr *pos, int id, int payload)
{
int offset = attr_to_offset(buf, pos);
int required = (offset - BLOB_COOKIE + sizeof(struct blob_attr) + payload) - buf->buflen;
...
}
static inline int
attr_to_offset(struct blob_buf *buf, struct blob_attr *attr)
{
return (char *)attr - (char *) buf->buf + BLOB_COOKIE;
}
It seems to me that the function attr_to_offset
calculates the offset between the start of the buffer and the position in the buffer of the new blob attribute. For some unknown reason, the integer constant BLOB_COOKIE is added to the returned value of attr_to_offset
(offset)
. However, BLOB_COOKIE
is again subtracted from the next value (offset - BLOB_COOKIE
). So it's as if we never added the value of BLOB_COOKIE, is it?