From: Joel Rosdahl Date: Sun, 8 May 2022 14:09:24 +0000 (+0200) Subject: refactor: Simplify Reader::read_int X-Git-Tag: v4.6.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49f9bdeaf9ca1b5b25cc922f768b995444c4c028;p=thirdparty%2Fccache.git refactor: Simplify Reader::read_int std::string::operator[](0) is well-defined for empty strings. --- diff --git a/src/core/Reader.hpp b/src/core/Reader.hpp index 291c35627..317005ef3 100644 --- a/src/core/Reader.hpp +++ b/src/core/Reader.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021 Joel Rosdahl and other contributors +// Copyright (C) 2021-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -72,11 +72,9 @@ inline std::string Reader::read_str(const size_t length) { std::string value(length, 0); - if (length > 0) { - const auto bytes_read = read(&value[0], length); - if (bytes_read != length) { - throw core::Error("Read underflow"); - } + const auto bytes_read = read(&value[0], length); + if (bytes_read != length) { + throw core::Error("Read underflow"); } return value; }