From 49f9bdeaf9ca1b5b25cc922f768b995444c4c028 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 8 May 2022 16:09:24 +0200 Subject: [PATCH] refactor: Simplify Reader::read_int std::string::operator[](0) is well-defined for empty strings. --- src/core/Reader.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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; } -- 2.47.2