add: if (chain == NULL) return B_BAD_VALUE;
context: cbuf_memcpy_from_chain(void *_dest, cbuf *chain, size_t offset, size_t length){	cbuf *buffer;	char *dest = (char *)_dest;	int bufferOffset;	if ((chain->flags & CBUF_FLAG_CHAIN_HEAD) == 0) {		dprintf("cbuf_memcpy_from_chain: chain at %p not head\n", chain);		return B_BAD_VALUE;	}	if (length + offset > chain->total_length) {		dprintf("cbuf_memcpy_from_chain: length + offset > size of cbuf chain\n");		return B_BAD_VALUE;	}	// find the starting cbuf in the chain to copy from	buffer = chain;	bufferOffset = 0;	while (offset > 0) {		if (buffer == NULL) {			dprintf("cbuf_memcpy_from_chain: end of chain reached too early!\n");			return B_ERROR;		}		if (offset < buffer->length) {			// this is the one			bufferOffset = offset;			break;		}		offset -= buffer->length;		buffer = buffer->next;	}	while (length > 0) {		int toCopy;		if (buffer == NULL) {			dprintf("cbuf_memcpy_from_chain: end of chain reached too early!\n");			return B_ERROR;		}		toCopy = min(length, buffer->length - bufferOffset);		memcpy(dest, (char *)buffer->data + bufferOffset, toCopy);		bufferOffset = 0;		length -= toCopy;		dest += toCopy;		buffer = buffer->next;	}	return B_OK;}