commit f93e893e19c95abce413ba634f8aa6872e4743e6
Author: Alan McGovern <alan.mcgov...@gmail.com>
Date:   Fri Sep 17 22:31:14 2010 +0100

    Prevent an overflow when marshalling datetimes.
    
    We know the itunes database can only represent 32bit times, so ensure
    that we only generate 32bit values for dates. Prevents throwing an
    overflow exception 32bit systems if we have a date too large for a
    32bit value. Fixes banshee bug #629838.

 bindings/mono/libgpod-sharp/GPodBase.cs |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/bindings/mono/libgpod-sharp/GPodBase.cs 
b/bindings/mono/libgpod-sharp/GPodBase.cs
index 7c27ce1..1fdffeb 100644
--- a/bindings/mono/libgpod-sharp/GPodBase.cs
+++ b/bindings/mono/libgpod-sharp/GPodBase.cs
@@ -39,12 +39,23 @@ namespace GPod {
                        ptr = GLib.Marshaller.StringToPtrGStrdup (str);
                }
                
-               protected static IntPtr DateTimeTotime_t (DateTime time) {
-                       return GLib.Marshaller.DateTimeTotime_t (time);
+               static DateTime local_epoch = new DateTime (1970, 1, 1, 0, 0, 
0);
+               static int utc_offset = (int) 
(TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now)).TotalSeconds;
+
+               public static IntPtr DateTimeTotime_t (DateTime time)
+               {
+                       // The itunes database uses a 32bit signed value, so 
enforce that here to avoid
+                       // overflow issues. We still need to represent time 
with an IntPtr though as
+                       // that's what libgpod publicly exposes
+                       return new IntPtr (((int)time.Subtract 
(local_epoch).TotalSeconds) - utc_offset);
                }
-               
-               protected static DateTime time_tToDateTime (IntPtr time_t) {
-                       return GLib.Marshaller.time_tToDateTime (time_t);
+
+               public static DateTime time_tToDateTime (IntPtr time_t)
+               {
+                       // The itunes database uses a 32bit signed value, so 
enforce that here to avoid
+                       // overflow issues. We still need to represent time 
with an IntPtr though as
+                       // that's what libgpod publicly exposes
+                       return local_epoch.AddSeconds (time_t.ToInt32 () + 
utc_offset);
                }
                
                internal IntPtr Native {

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to