Fix a buffer overflow handling strings larger than 40 characters