Don't access non-existing element buf[256], use buf[255] instead.