From ee06530b5244f2b91c9519ccec9bf472d35f018a Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sun, 17 Nov 2013 13:27:04 +0100 Subject: [PATCH] glib: Avoid doing the same cast twice in KeyFile.ToData The cast from UIntPtr to int can fail at runtime, but if your config file is more than 2^31 bytes, you probably have bigger problems... --- glib/KeyFile.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/glib/KeyFile.cs b/glib/KeyFile.cs index 23245ebf8..7f5018cb2 100644 --- a/glib/KeyFile.cs +++ b/glib/KeyFile.cs @@ -531,9 +531,10 @@ namespace GLib { public byte[] ToData () { UIntPtr native_length; - IntPtr raw_ret = g_key_file_to_data(Handle, out native_length, IntPtr.Zero); - byte[] ret = new byte [(int) native_length]; - Marshal.Copy (raw_ret, ret, 0, (int) native_length); + IntPtr raw_ret = g_key_file_to_data (Handle, out native_length, IntPtr.Zero); + int length = (int)native_length; + byte[] ret = new byte [length]; + Marshal.Copy (raw_ret, ret, 0, length); Marshaller.Free (raw_ret); return ret; }