This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch tqchen/printer-refinement
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/tqchen/printer-refinement by
this push:
new 50b29bf5e2 Read metadata slots through checked integer conversion
50b29bf5e2 is described below
commit 50b29bf5e22dcd052d0203708a35a7a3effafb14
Author: Tianqi Chen <[email protected]>
AuthorDate: Thu Oct 1 23:02:23 2026 +0000
Read metadata slots through checked integer conversion
---
src/script/printer/printer.cc | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/script/printer/printer.cc b/src/script/printer/printer.cc
index 43821facd6..8269f0745e 100644
--- a/src/script/printer/printer.cc
+++ b/src/script/printer/printer.cc
@@ -91,14 +91,14 @@ ffi::Map<ffi::String, ffi::Array<ffi::Any>> CollectMetadata(
if (!id || origins.count(id.value()) || !key_doc || !index_doc) return;
auto key = key_doc.value()->value.as<ffi::String>();
const auto* index = index_doc.value()->value.as<IntImmNode>();
- if (!key || key.value() != original.value()->GetTypeKey() || !index ||
index->value < 0)
- return;
+ if (!key || key.value() != original.value()->GetTypeKey() || !index)
return;
+ auto slot = index->value.as<int64_t>();
+ if (!slot.has_value() || slot.value() < 0) return;
if (metadata_id->has_value() &&
!metadata_id->value().same_as(id.value())) return;
*metadata_id = id;
auto values =
metadata.Get(key.value()).value_or(ffi::Array<ffi::Any>{});
- size_t slot = static_cast<size_t>(index->value);
- while (values.size() <= slot) values.push_back(nullptr);
- values.Set(slot, original.value());
+ while (values.size() <= static_cast<size_t>(slot.value()))
values.push_back(nullptr);
+ values.Set(slot.value(), original.value());
metadata.Set(key.value(), values);
},
&visited);