Testing against chunk + strlen(chunk) is horrible :-(
You're making a linear traversal quadratic.
Save <code> const char * stop = chunk + strlen(chunk); </code> before entering the loop and test <code> sp <= stop </code>