Fixed buffer bug in C++