sd: Fix overflow of sd_write_buffer

This variable was allowed to grow without bound, meaning it eventually
would overflow and cause a segfault.  We now ensure it's within a good
range when incrementing or setting this pointer.