Check for E_NOMEM conditions.

This commit is contained in:
Dianne Skoll
2023-03-02 09:43:56 -05:00
parent afc1667e64
commit 87e392de6c

View File

@@ -1169,15 +1169,27 @@ static int FPad(func_info *info)
if (Nargs < 4 || !ARGV(3)) {
/* Pad on the LEFT */
for (i=0; i<wantlen-len; i++) {
DBufPutc(&dbuf, *s++);
if (DBufPutc(&dbuf, *s++) != OK) {
DBufFree(&dbuf);
return E_NO_MEM;
}
if (!*s) s = ARGSTR(1);
}
DBufPuts(&dbuf, ARGSTR(0));
if (DBufPuts(&dbuf, ARGSTR(0)) != OK) {
DBufFree(&dbuf);
return E_NO_MEM;
}
} else {
/* Pad on the RIGHT */
DBufPuts(&dbuf, ARGSTR(0));
if (DBufPuts(&dbuf, ARGSTR(0)) != OK) {
DBufFree(&dbuf);
return E_NO_MEM;
}
for (i=0; i<wantlen-len; i++) {
DBufPutc(&dbuf, *s++);
if (DBufPutc(&dbuf, *s++) != OK) {
DBufFree(&dbuf);
return E_NO_MEM;
}
if (!*s) s = ARGSTR(1);
}
}