The slice function now returns bad on out of bounds.

Added an extra type cast to a buf_add call for compatibility with some stricter
compile optionsi (e.g. -Wconversion etc.)  I'm not using those options in this
release though because I still need it to compile on an older machine with a
gcc that doesn't yet support them.