`assert(lower <= upper && upper <= bufLen);`

I know it's assertive code, but if this is meant to be used in a tight loop, we might as well not gratuitously slow it down in non-release.