@@ -123,6 +123,31 @@ TEST(BasicTypes, ConvertFromString_Double)
123123 ASSERT_THROW ((void )convertFromString<double >(" not_a_number" ), RuntimeError);
124124}
125125
126+ TEST (BasicTypes, DoubleToIntBoundary)
127+ {
128+ // A double that lands exactly on 2^63 must be rejected before the cast, not
129+ // static_cast to int64_t (which is out of range and undefined behavior).
130+ // 2^63 = 9223372036854775808.0; INT64_MAX is 9223372036854775807.
131+ const double two_pow_63 = 9223372036854775808.0 ;
132+ EXPECT_ANY_THROW ((void )BT::Any (two_pow_63).cast <int64_t >());
133+
134+ // 2^64 lands one past UINT64_MAX and must likewise be rejected.
135+ const double two_pow_64 = 18446744073709551616.0 ;
136+ EXPECT_ANY_THROW ((void )BT::Any (two_pow_64).cast <uint64_t >());
137+
138+ // In-range integral doubles still convert cleanly.
139+ const double in_range = 4611686018427387904.0 ; // 2^62
140+ EXPECT_EQ (BT::Any (in_range).cast <int64_t >(), int64_t (4611686018427387904LL ));
141+ EXPECT_EQ (BT::Any (1000.0 ).cast <int64_t >(), int64_t (1000 ));
142+
143+ // Same boundary reached through Blackboard::set, which routes the numeric
144+ // safe-cast check (isCastingSafe/ValidCast) instead of Any::convert.
145+ auto bb = BT::Blackboard::create ();
146+ bb->set (" k" , int64_t (1 )); // lock the entry to int64_t
147+ EXPECT_ANY_THROW (bb->set (" k" , two_pow_63));
148+ EXPECT_NO_THROW (bb->set (" k" , in_range));
149+ }
150+
126151TEST (BasicTypes, ConvertFromString_Bool)
127152{
128153 ASSERT_TRUE (convertFromString<bool >(" true" ));
0 commit comments