[vala/staging: 2/3] codegen: Dup arrays only if length > 0, this consistently returns NULL (POSIX)



commit 18847c9221362081c9a9d37e2922f3e3ea648088
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun May 24 19:25:41 2020 +0200

    codegen: Dup arrays only if length > 0, this consistently returns NULL (POSIX)

 codegen/valaccodearraymodule.vala | 7 +++++++
 1 file changed, 7 insertions(+)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 5fa9ea23d..ee0fa7780 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -529,6 +529,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                push_context (new EmitContext ());
                push_function (function);
 
+               // only attempt to dup if length > 0, this consistently returns NULL
+               var clengthcheck = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, new 
CCodeIdentifier ("length"), new CCodeConstant ("0"));
+               ccode.open_if (clengthcheck);
+
                if (requires_copy (array_type.element_type)) {
                        var cvardecl = new CCodeVariableDeclarator ("result");
                        CCodeFunctionCall gnew;
@@ -599,6 +603,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        }
                }
 
+               ccode.close ();
+               ccode.add_return (new CCodeIdentifier ("NULL"));
+
                // append to file
 
                cfile.add_function_declaration (function);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]