Fix potential issue when hostname string is shorter than supplied length

Apparently this was causing hangs.