Fix bug in buffer.c, add buffer mini-unit test.