Don't you need to add a "\0" here? Otherwise depending on what is in memory the cstring could have some random bytes at the end.