From 7c1f423014003e2bf4ed2feb7520b3355c834fed Mon Sep 17 00:00:00 2001 From: Josh Nohle Date: Fri, 16 Jul 2021 14:21:48 -0700 Subject: [PATCH] [Nearby Connections][C++] Fix integer comparison and includes PiperOrigin-RevId: 385222885 --- cpp/core/payload.h | 3 ++- cpp/platform/base/input_stream.cc | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cpp/core/payload.h b/cpp/core/payload.h index 27307959..7eae23aa 100644 --- a/cpp/core/payload.h +++ b/cpp/core/payload.h @@ -25,6 +25,7 @@ #include "platform/base/payload_id.h" #include "platform/base/prng.h" #include "platform/public/file.h" +#include "platform/public/logging.h" #include "absl/types/variant.h" namespace location { @@ -94,7 +95,7 @@ class Payload { CHECK(type_ == Type::kFile || type_ == Type::kStream); InputFile* file = AsFile(); if (file != nullptr) { - CHECK(offset < file->GetTotalSize()); + CHECK(file->GetTotalSize() > 0 && offset < (size_t)file->GetTotalSize()); } offset_ = offset; } diff --git a/cpp/platform/base/input_stream.cc b/cpp/platform/base/input_stream.cc index 23100136..c3d75693 100644 --- a/cpp/platform/base/input_stream.cc +++ b/cpp/platform/base/input_stream.cc @@ -14,6 +14,7 @@ #include "platform/base/input_stream.h" +#include #include #include @@ -22,8 +23,9 @@ namespace location { namespace nearby { - +namespace { constexpr size_t kSkipBufferSize = 64 * 1024; +} // namespace ExceptionOr InputStream::Skip(size_t offset) { size_t bytes_left = offset;