[ccan] Add new 'bytestring' module

Jonathan Nieder jrnieder at gmail.com
Mon May 21 13:28:38 EST 2012


Hi,

David Gibson wrote:

> --- /dev/null
> +++ b/ccan/bytestring/_info
> @@ -0,0 +1,36 @@
[...]
> + * Because of this use case, the bytestrings are treated as having
> + * immutable contents (we use a const char pointer).  The caller code
> + * is responsible for ensuring that the lifetime of the data
> + * referenced by the bytestrings is long enough not to leave
> + * bytestring structures with a dangling pointer.

Neat.  So these are the "memory areas" that functions like memcpy and
memmem manipulate, and as this library improves it might grow to
include various examples of how to safely modify their content without
buffer overflows.

For some reason when I heard the name bytestring it made me think of
git's strbuf type --- a binary-safe growing buffer that always
maintains a '\0' byte at the end:

	extern char strbuf_slopbuf[];
	struct strbuf {
		size_t alloc;
		size_t len;
		char *buf;
	};

	#define STRBUF_INIT  { 0, 0, strbuf_slopbuf }

(By the way, I think that would be a great candidate for assimilation
if someone wants to try it.)

Maybe some name like memarea would avoid ambiguity.

My two cents,
Jonathan


More information about the ccan mailing list