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...
This commit is contained in:
Bertrand Lorentz 2013-11-17 13:27:04 +01:00
parent f1005da47c
commit ee06530b52

View File

@ -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;
}