]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/longlong.cpp
fixing overrelease and out-of-bounds write, fixes #13725
[wxWidgets.git] / src / common / longlong.cpp
index 27e771096da29796855d956a49d19cc88c1449c8..1ceefe012303c0677d29e8b557b4face30673d26 100644 (file)
@@ -133,6 +133,22 @@ wxULongLongNative& wxULongLongNative::operator=(const class wxULongLongWx &ll)
 }
 #endif
 
+#ifdef __VISUALC6__
+double wxULongLongNative::ToDouble() const
+{
+    // Work around the problem of casting unsigned __int64 to double in VC6
+    // (which for unknown reasons only manifests itself in DLL builds, i.e.
+    // when using /MD).
+    static const __int64 int64_t_max = 9223372036854775807i64;
+    if ( m_ll <= int64_t_max )
+        return wx_truncate_cast(double, (wxLongLong_t)m_ll);
+
+    double d = wx_truncate_cast(double, int64_t_max);
+    d += (__int64)(m_ll - int64_t_max - 1); // The cast is safe because of -1
+    return d + 1;
+}
+#endif // __VISUALC6__
+
 #endif // wxUSE_LONGLONG_NATIVE
 
 // ============================================================================