Fixed undefined behavior of returned pointer
Fixed some uninitialized values
Avoid const_cast, static buffer and buffer overlap
Merge pull request #431 from Kratos714/master

Fixed some minor memory issues