visionmedia/buffer.c — pull request #2 by deltheil (2013-01-08 22:50:29+00:00)
Title: Extra slot for null terminator

Since the `data` attribute is manipulated as a character string (and used as input for `strlen`, `strcmp`, ...) every library function that **directly** (re)allocates the internal buffer should take care to include an extra slot filled with the null terminator.

The following functions are concerned and have been modified accordingly:
* `buffer_new_with_size`
* `buffer_compact`
* `buffer_resize`

By doing this there is no need to allocate such an extra space for `buffer_slice` anymore since it does not *directly* handle the internal buffer.

This patch solves all Valgrind errors (invalid read, etc) due to the fact that `data` was not guaranteed to always be null terminated.