[smalloc] Define kMaxLength constant
[buffer] Make read.../write... methods aware of kMaxLength

Also catch negative offsets.
[buffer] Fix handling of out of range indexes in slice()
[buffer] Refactor slice() method
[buffer] Replace qMin() with std::min()