From 731db8b64403c06c36a27c6a73b13c4b04a9aacd Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Tue, 2 Apr 2019 16:47:36 +0200 Subject: [PATCH] csharp: Raise exception when Array is null. Reviewers: felipealmeida, vitor.sousa, segfaultxavi Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8499 --- src/bindings/mono/eina_mono/eina_array.cs | 10 ++++++++++ src/tests/efl_mono/Eina.cs | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs index f4dd49d69e..b2cdede565 100644 --- a/src/bindings/mono/eina_mono/eina_array.cs +++ b/src/bindings/mono/eina_mono/eina_array.cs @@ -99,6 +99,11 @@ public class Array : IEnumerable, IDisposable public Array(IntPtr handle, bool own) { + if (handle == IntPtr.Zero) + { + throw new ArgumentNullException("Handle can't be null"); + } + Handle = handle; Own = own; OwnContent = own; @@ -106,6 +111,11 @@ public class Array : IEnumerable, IDisposable public Array(IntPtr handle, bool own, bool ownContent) { + if (handle == IntPtr.Zero) + { + throw new ArgumentNullException("Handle can't be null"); + } + Handle = handle; Own = own; OwnContent = ownContent; diff --git a/src/tests/efl_mono/Eina.cs b/src/tests/efl_mono/Eina.cs index 8b7f1a9672..6a07e2f288 100644 --- a/src/tests/efl_mono/Eina.cs +++ b/src/tests/efl_mono/Eina.cs @@ -460,6 +460,12 @@ class TestEinaArray Test.Assert(a.Handle != IntPtr.Zero); } + public static void create_array_from_null() + { + Test.AssertRaises(() => new Eina.Array(IntPtr.Zero, false)); + Test.AssertRaises(() => new Eina.Array(IntPtr.Zero, false, false)); + } + public static void push_int() { var a = new Eina.Array();