From 9b4e1eae9e34c04b1bbcdbbfba336ba329a04d3f Mon Sep 17 00:00:00 2001 From: James Ward Date: Mon, 25 Mar 2024 17:50:33 +0000 Subject: [PATCH] Fix C4267 warnings in Visual Studio on WIN32 --- tiny_gltf.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 7ef28f4..5e63839 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -337,12 +337,11 @@ class Value { T &Get(); // Lookup value from an array - const Value &Get(int idx) const { + const Value &Get(size_t idx) const { static Value null_value; assert(IsArray()); - assert(idx >= 0); - return (static_cast(idx) < array_value_.size()) - ? array_value_[static_cast(idx)] + return (idx < array_value_.size()) + ? array_value_[idx] : null_value; } @@ -1927,7 +1926,7 @@ static bool Equals(const tinygltf::Value &one, const tinygltf::Value &other) { } case ARRAY_TYPE: { if (one.Size() != other.Size()) return false; - for (int i = 0; i < int(one.Size()); ++i) + for (size_t i = 0; i < one.Size(); ++i) if (!Equals(one.Get(i), other.Get(i))) return false; return true; } @@ -7070,10 +7069,10 @@ static bool ValueToJson(const Value &value, detail::json *ret) { obj = detail::json(value.Get()); break; case ARRAY_TYPE: { - for (unsigned int i = 0; i < value.ArrayLen(); ++i) { - Value elementValue = value.Get(int(i)); + for (size_t i = 0; i < value.ArrayLen(); ++i) { + Value elementValue = value.Get(i); detail::json elementJson; - if (ValueToJson(value.Get(int(i)), &elementJson)) + if (ValueToJson(value.Get(i), &elementJson)) obj.push_back(elementJson); } break;