Make trim >31-bit offset safe
Make trim >31-bit offset safe

This also cleans up some code that at first glance looks wrong.

michaelkschmidt/fwup,fhunleth/fwup,fhunleth/fwup,michaelkschmidt/fwup,michaelkschmidt/fwup,fhunleth/fwup