c++: Fix possible string truncation