Fix bug that caused emscripten_get_callstack to not truncate the output buffer. Add test. Closes #2171.