From c5c66dfbf5bcb3955e7ba8a0f7fbba474683d220 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 6 Dec 2023 19:00:04 +0100 Subject: [PATCH] exslt: Fix EXSLT functions without parameters Fix regression from commit 7364666b on platforms where malloc(0) returns NULL. Should fix #100. --- libexslt/functions.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libexslt/functions.c b/libexslt/functions.c index 9497d7e0..56f1dbdb 100644 --- a/libexslt/functions.c +++ b/libexslt/functions.c @@ -385,13 +385,15 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) { newBase = tctxt->varsNr; /* If there are any parameters */ if (paramNode != NULL) { - args = (xmlXPathObjectPtr *) xmlMalloc(sizeof(*args) * nargs); - if (args == NULL) - goto error; - /* Fetch the stored argument values from the caller */ - for (i = nargs - 1; i >= 0; i--) { - args[i] = valuePop(ctxt); - } + if (nargs > 0) { + args = (xmlXPathObjectPtr *) xmlMalloc(sizeof(*args) * nargs); + if (args == NULL) + goto error; + /* Fetch the stored argument values from the caller */ + for (i = nargs - 1; i >= 0; i--) { + args[i] = valuePop(ctxt); + } + } /* * Prepare to process params in reverse order. First, go to