Memory corruption due to undersized buffer