Skip to content

Commit 07e09fc

Browse files
committed
Merge in comments from cfengine#1
1 parent 7ea2f28 commit 07e09fc

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

libpromises/evalfunction.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,19 +1417,11 @@ static FnCallResult FnCallTextXform(ARG_UNUSED EvalContext *ctx, ARG_UNUSED cons
14171417
{
14181418
char *buf = NULL;
14191419
char *string = RlistScalarValue(finalargs);
1420-
FnCallResult ret;
14211420
size_t len = strlen(string);
1422-
size_t bufsiz = len + 1 < 2 ? 2 : len + 1;
1423-
1424-
if (len > CF_INFINITY)
1425-
{
1426-
free(buf);
1427-
Log(LOG_LEVEL_ERR, "%s: unable to parse without truncating", fp->name);
1428-
return FnFailure();
1429-
}
1421+
size_t bufsiz = MAX(len + 1, PRINTSIZE(len));
14301422

14311423
buf = xcalloc(bufsiz, sizeof(char));
1432-
(void)strlcpy(buf, string, bufsiz);
1424+
memcpy(buf, string, len);
14331425

14341426
if (!strcmp(fp->name, "string_downcase"))
14351427
{
@@ -1474,7 +1466,7 @@ static FnCallResult FnCallTextXform(ARG_UNUSED EvalContext *ctx, ARG_UNUSED cons
14741466
const long max = IntFromString(RlistScalarValue(finalargs->next));
14751467
if (max < len)
14761468
{
1477-
strncpy(buf, string + len - max, len);
1469+
memcpy(buf, string + len - max, max + 1);
14781470
}
14791471
}
14801472
else
@@ -1484,9 +1476,7 @@ static FnCallResult FnCallTextXform(ARG_UNUSED EvalContext *ctx, ARG_UNUSED cons
14841476
return FnFailure();
14851477
}
14861478

1487-
ret = FnReturn(buf);
1488-
free(buf);
1489-
return ret;
1479+
return FnReturnNoCopy(buf);
14901480
}
14911481

14921482
/*********************************************************************/
@@ -5248,7 +5238,7 @@ static FnCallResult FnCallReadFile(ARG_UNUSED EvalContext *ctx, ARG_UNUSED const
52485238
{
52495239
char *filename = RlistScalarValue(finalargs);
52505240
char *requested_max = RlistScalarValue(finalargs->next);
5251-
int maxsize = IntFromString(requested_max);
5241+
long maxsize = IntFromString(requested_max);
52525242

52535243
if (maxsize > CF_INFINITY)
52545244
{

0 commit comments

Comments
 (0)