Bounds checks: add (failing) unit tests, then fix them

The fixes stop accepting bogus -ve values to functions 'sub', 'shift', 'add_len', 'set_len'.