]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Simplify Reader::read_int
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 8 May 2022 14:09:24 +0000 (16:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 8 May 2022 14:12:41 +0000 (16:12 +0200)
std::string::operator[](0) is well-defined for empty strings.

src/core/Reader.hpp

index 291c356270db4d1af88226f1df32de56642a0cfe..317005ef3dbccd87e8c77b08d336bb2b82d654b8 100644 (file)
@@ -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;
 }