Skip to content

Commit c49cec4

Browse files
committed
readtags: use e* functions declared in routines.h
The original code just calls perror when stdlib allocators return NULL. As a command, readtags should stop its execution in such cases. This change replaces the stdlib allocators with e* allocators declared in routines.h. e* allocators call exit(3) when their allocations are failed. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 4089cff commit c49cec4

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

extra-cmds/readtags-cmd.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,33 @@ static tagEntry *copyTag (tagEntry *o)
107107
{
108108
tagEntry *n;
109109

110-
n = calloc (1, sizeof (*o));
111-
if (!n)
112-
perror (__FUNCTION__);
110+
n = eCalloc (1, sizeof (*o));
113111

114-
n->name = strdup (o->name);
115-
116-
if (!n->name)
117-
perror (__FUNCTION__);
112+
n->name = eStrdup (o->name);
118113

119114
if (o->file)
120-
n->file = strdup (o->file);
121-
if (o->file && !n->file)
122-
perror (__FUNCTION__);
115+
n->file = eStrdup (o->file);
123116

124117
if (o->address.pattern)
125-
{
126-
n->address.pattern = strdup (o->address.pattern);
127-
if (!n->address.pattern)
128-
perror (__FUNCTION__);
129-
}
118+
n->address.pattern = eStrdup (o->address.pattern);
130119

131120
n->address.lineNumber = o->address.lineNumber;
132121

133122
if (o->kind)
134-
{
135-
n->kind = strdup (o->kind);
136-
if (!n->kind)
137-
perror (__FUNCTION__);
138-
}
123+
n->kind = eStrdup (o->kind);
139124

140125
n->fileScope = o->fileScope;
141126
n->fields.count = o->fields.count;
142127

143128
if (o->fields.count == 0)
144129
return n;
145130

146-
n->fields.list = malloc (o->fields.count *sizeof (*o->fields.list));
147-
if (!n->fields.list)
148-
perror (__FUNCTION__);
131+
n->fields.list = eMalloc (o->fields.count * sizeof (*o->fields.list));
149132

150133
for (unsigned short c = 0; c < o->fields.count; c++)
151134
{
152-
n->fields.list[c].key = strdup (o->fields.list[c].key);
153-
if (!n->fields.list[c].key)
154-
perror (__FUNCTION__);
155-
156-
n->fields.list[c].value = strdup (o->fields.list[c].value);
157-
if (!n->fields.list[c].value)
158-
perror (__FUNCTION__);
135+
n->fields.list[c].key = eStrdup (o->fields.list[c].key);
136+
n->fields.list[c].value = eStrdup (o->fields.list[c].value);
159137
}
160138

161139
return n;
@@ -172,15 +150,11 @@ struct tagEntryArray {
172150

173151
struct tagEntryArray *tagEntryArrayNew (void)
174152
{
175-
struct tagEntryArray * a = malloc (sizeof (struct tagEntryArray));
176-
if (!a)
177-
perror(__FUNCTION__);
153+
struct tagEntryArray * a = eMalloc (sizeof (struct tagEntryArray));
178154

179155
a->count = 0;
180156
a->length = 1024;
181-
a->a = malloc(a->length * sizeof (a->a[0]));
182-
if (!a->a)
183-
perror(__FUNCTION__);
157+
a->a = eMalloc(a->length * sizeof (a->a[0]));
184158

185159
return a;
186160
}
@@ -192,10 +166,7 @@ void tagEntryArrayPush (struct tagEntryArray *a, tagEntry *e)
192166
if (a->length * 2 < a->length)
193167
perror("Too large array allocation");
194168

195-
struct tagEntryHolder *tmp = realloc (a->a, sizeof (a->a[0]) * (a->length * 2));
196-
if (!tmp)
197-
perror(__FUNCTION__);
198-
169+
struct tagEntryHolder *tmp = eRealloc (a->a, sizeof (a->a[0]) * (a->length * 2));
199170
a->a = tmp;
200171
a->length *= 2;
201172
}

0 commit comments

Comments
 (0)