summaryrefslogtreecommitdiff
path: root/expr.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-10 16:10:01 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-03 11:02:06 -0800
commit81e46cab5f4bdd69fa0a644dba86f6902cece175 (patch)
tree3f664cb6d78c4a2cccbe9ef2be153e3df9633fc9 /expr.c
parenta1551b78e9ac0e2075ca241c0e8ae361758f26b4 (diff)
Use asprintf() if the platform supports it
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/expr.c b/expr.c
index 8351f2c..4af45c3 100644
--- a/expr.c
+++ b/expr.c
@@ -762,13 +762,20 @@ ExprResolveString(ExprDef * expr,
if (ExprResolveString(left, &leftRtrn, lookup, lookupPriv) &&
ExprResolveString(right, &rightRtrn, lookup, lookupPriv))
{
- int len;
char *new;
- len = strlen(leftRtrn.str) + strlen(rightRtrn.str) + 1;
+
+#ifdef HAVE_ASPRINTF
+ if (asprintf(&new, "%s%s", leftRtrn.str, rightRtrn.str) < 0)
+ new = NULL;
+#else
+ size_t len = strlen(leftRtrn.str) + strlen(rightRtrn.str) + 1;
new = malloc(len);
+#endif
if (new)
{
+#ifndef HAVE_ASPRINTF
snprintf(new, len, "%s%s", leftRtrn.str, rightRtrn.str);
+#endif
val_rtrn->str = new;
return True;
}