make use of en*alloc functions
This commit is contained in:
parent
c0a3c66a84
commit
0fcad66c75
8
expr.c
8
expr.c
@ -115,9 +115,7 @@ match(Val vstr, Val vregx)
|
||||
str = valstr(vstr, buf1, sizeof(buf1));
|
||||
regx = valstr(vregx, buf2, sizeof(buf2));
|
||||
|
||||
anchreg = malloc(strlen(regx) + 2);
|
||||
if (!anchreg)
|
||||
enprintf(3, "malloc:");
|
||||
anchreg = enmalloc(3, strlen(regx) + 2);
|
||||
snprintf(anchreg, strlen(regx) + 2, "^%s", regx);
|
||||
|
||||
enregcomp(3, &re, anchreg, 0);
|
||||
@ -131,9 +129,7 @@ match(Val vstr, Val vregx)
|
||||
if (re.re_nsub) {
|
||||
regfree(&re);
|
||||
len = matches[1].rm_eo - matches[1].rm_so + 1;
|
||||
ret = malloc(len);
|
||||
if (!ret)
|
||||
enprintf(3, "malloc:");
|
||||
ret = enmalloc(3, len);
|
||||
strlcpy(ret, str + matches[1].rm_so, len);
|
||||
d = strtoimax(ret, &p, 10);
|
||||
if (*ret && !*p) {
|
||||
|
16
grep.c
16
grep.c
@ -162,18 +162,14 @@ addpattern(const char *pattern)
|
||||
pattern = ".";
|
||||
|
||||
if (!Fflag && xflag) {
|
||||
tmp = malloc(strlen(pattern) + 3);
|
||||
if (!tmp)
|
||||
enprintf(Error, "malloc:");
|
||||
tmp = enmalloc(Error, strlen(pattern) + 3);
|
||||
snprintf(tmp, strlen(pattern) + 3, "%s%s%s",
|
||||
pattern[0] == '^' ? "" : "^",
|
||||
pattern,
|
||||
pattern[strlen(pattern) - 1] == '$' ? "" : "$");
|
||||
} else if (!Fflag && wflag) {
|
||||
len = strlen(pattern) + 5 + (Eflag ? 2 : 4);
|
||||
tmp = malloc(len);
|
||||
if (!tmp)
|
||||
enprintf(Error, "malloc:");
|
||||
tmp = enmalloc(Error, len);
|
||||
|
||||
bol = eol = 0;
|
||||
if (pattern[0] == '^')
|
||||
@ -188,14 +184,10 @@ addpattern(const char *pattern)
|
||||
Eflag ? ")" : "\\)",
|
||||
eol ? "$" : "");
|
||||
} else {
|
||||
tmp = strdup(pattern);
|
||||
if (!tmp)
|
||||
enprintf(Error, "strdup:");
|
||||
tmp = enstrdup(Error, pattern);
|
||||
}
|
||||
|
||||
pnode = malloc(sizeof(*pnode));
|
||||
if (!pnode)
|
||||
enprintf(Error, "malloc:");
|
||||
pnode = enmalloc(Error, sizeof(*pnode));
|
||||
pnode->pattern = tmp;
|
||||
SLIST_INSERT_HEAD(&phead, pnode, entry);
|
||||
}
|
||||
|
9
sort.c
9
sort.c
@ -131,9 +131,7 @@ addkeydef(char *def, int flags)
|
||||
{
|
||||
struct kdlist *node;
|
||||
|
||||
node = malloc(sizeof(*node));
|
||||
if (!node)
|
||||
enprintf(2, "malloc:");
|
||||
node = enmalloc(2, sizeof(*node));
|
||||
if (!head)
|
||||
head = node;
|
||||
if (parse_keydef(&node->keydef, def, flags))
|
||||
@ -282,7 +280,6 @@ static char *
|
||||
columns(char *line, const struct keydef *kd)
|
||||
{
|
||||
char *start, *end;
|
||||
char *res;
|
||||
int i;
|
||||
|
||||
for (i = 1, start = line; i < kd->start_column; i++)
|
||||
@ -305,7 +302,5 @@ columns(char *line, const struct keydef *kd)
|
||||
end = strchr(line, '\0');
|
||||
}
|
||||
|
||||
if (!(res = strndup(start, end - start)))
|
||||
enprintf(2, "strndup:");
|
||||
return res;
|
||||
return enstrndup(2, start, end - start);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user