base: fix bug in String::valid()

String::valid() does not check whether _length is zero.
Consequently, this leads to _buf[-1] being evaluated.
This commit is contained in:
Johannes Schlatow 2014-03-26 18:53:39 +01:00 committed by Christian Helmuth
parent e6c7596af5
commit 2262eb8347

View File

@ -479,7 +479,7 @@ namespace Genode {
static constexpr size_t capacity() { return CAPACITY; }
bool valid() const {
return (_length <= CAPACITY) && (_buf[_length - 1] == '\0'); }
return (_length <= CAPACITY) && (_length != 0) && (_buf[_length - 1] == '\0'); }
char const *string() const { return valid() ? _buf : ""; }