NUL terminate buffer before calling atoi