Avoid using deprecated constructor
Added a test case which tests if buffer overflowed.
remove garbage codes (unnecessary cast).