Fix buffer overflow and exception throwing on success.

Signed-off-by: Thorben Hasenpusch <thorben.hasenpusch@gmail.com>