[ldns-users] ldns_buffer2str asserting after ldns_buffer_copy

Karel Slany karel.slany at nic.cz
Fri Jul 20 12:43:59 UTC 2012


Hello again,

I'm writing some scripts for automated checking of pyLDNS basic
functionality. I have encountered strange behaviour of the
ldns_buffer_copy and ldns_buffer2str function.

ldns_buffer: ./buffer.c:82: ldns_buffer_reserve: Assertion
`!buffer->_fixed' failed.

I am not sure whether this is a bug or I am missing something. But I
haven't found any clues in the documentation telling me why this
shouldn't work.

I've rewritten the code to C, in order to make it more understandable:

#include <stdio.h>
#include <ldns/ldns.h>

int main(void)
{
	ldns_buffer *b1, *b2;
	char *str;

	b1 = ldns_buffer_new(1024);
	b2 = ldns_buffer_new(10);

	ldns_buffer_printf(b1, "%s", "abc");
	ldns_buffer_printf(b2, "%s", "def");

	str = ldns_buffer2str(b1);
	fprintf(stdout, "b1: %s\n", str);
	LDNS_FREE(str);

	str = ldns_buffer2str(b2);
	fprintf(stdout, "b2: %s\n", str);
	LDNS_FREE(str);

	ldns_buffer_copy(b1, b2);

	str = ldns_buffer2str(b1); /* Asserts here. */
	fprintf(stdout, "b1: %s\n", str);
	LDNS_FREE(str);

	str = ldns_buffer2str(b2);
	fprintf(stdout, "b2: %s\n", str);
	LDNS_FREE(str);

	ldns_buffer_free(b1);
	ldns_buffer_free(b2);
}

The comment shows the position, where the code is asserting.

I've tested ldns 1.6.13 and also the latest SVN (revision 3707), both
behave the same.

K.



More information about the ldns-users mailing list