Fixed a crash when passing null as an std::string on Unix
@ -2743,6 +2743,15 @@ namespace CppSharp.Generators.CSharp
}
// special validation when constructing std::string as it cannot take null as a value
if (method != null && method.OriginalName == "basic_string" &&
method.TranslationUnit.IsSystemHeader)
{
WriteLine($"if (ReferenceEquals({method.Parameters[0].Name}, null))");
WriteLineIndent($@"throw new global::System.ArgumentNullException({
method.Parameters[0].Name}, ""The underlying std::string cannot take null."");");
if (needsReturn && !originalFunction.HasIndirectReturnTypeParameter)
Write("var {0} = ", Helpers.ReturnIdentifier);
@ -765,6 +765,15 @@ This is a very long string. This is a very long string. This is a very long stri
[Test, Platform(Exclude = "Win")]
public void TestNullStdString()
using (var hasStdString = new HasStdString())
Assert.That(() => hasStdString.TestStdString(null), Throws.ArgumentNullException);
private class CustomDerivedFromVirtual : AbstractWithVirtualDtor
public override void Abstract()