This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git


The following commit(s) were added to refs/heads/main by this push:
     new 88d5130  fix: Use-after-move when handling std::tuple (#293)
88d5130 is described below

commit 88d5130d4c640ef157d80cb9b612df4c8050fed4
Author: Junru Shao <[email protected]>
AuthorDate: Sun Nov 30 09:20:04 2025 -0800

    fix: Use-after-move when handling std::tuple (#293)
    
    See: https://github.com/apache/tvm-ffi/pull/228#discussion_r2573338636
---
 include/tvm/ffi/extra/stl.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/tvm/ffi/extra/stl.h b/include/tvm/ffi/extra/stl.h
index 523f77f..462e699 100644
--- a/include/tvm/ffi/extra/stl.h
+++ b/include/tvm/ffi/extra/stl.h
@@ -122,7 +122,11 @@ struct TypeTraits<details::ListTemplate> : public 
details::STLTypeTrait {
     auto array = ArrayObj::Empty(static_cast<std::int64_t>(sizeof...(Is)));
     auto dst = array->MutableBegin();
     // increase size after each new to ensure exception safety
-    ((::new (dst++) Any(std::get<Is>(std::forward<Tuple>(src))), 
array->size_++), ...);
+    std::apply(
+        [&](auto&&... elems) {
+          ((::new (dst++) Any(std::forward<decltype(elems)>(elems)), 
array->size_++), ...);
+        },
+        std::forward<Tuple>(src));
     return array;
   }
 
@@ -265,9 +269,9 @@ struct TypeTraits<std::vector<T>> : public 
TypeTraits<details::ListTemplate> {
       auto array = CopyFromAnyImpl<ArrayObj>(src);
       auto begin = array->MutableBegin();
       auto result = Self{};
-      auto length = array->size_;
+      int64_t length = array->size_;
       result.reserve(length);
-      for (std::size_t i = 0; i < length; ++i) {
+      for (int64_t i = 0; i < length; ++i) {
         result.emplace_back(ConstructFromAny<T>(begin[i]));
       }
       return result;

Reply via email to