diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-10 16:10:01 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-03 11:02:06 -0800 |
commit | 81e46cab5f4bdd69fa0a644dba86f6902cece175 (patch) | |
tree | 3f664cb6d78c4a2cccbe9ef2be153e3df9633fc9 /expr.c | |
parent | a1551b78e9ac0e2075ca241c0e8ae361758f26b4 (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.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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; } |