addressed issues reported by Coverity.

all minor.
improved formatting.
properly handle wrapping in foundation::find_next_available_path() and added unit tests.