Skip to content

Commit 8334234

Browse files
authored
Merge pull request #3501 from masatake/readtags--use-e-memory-allocator
readtags: use e* memory allocators like eMalloc declared in routines.h
2 parents 4089cff + 1baeac2 commit 8334234

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

extra-cmds/readtags-cmd.c

Lines changed: 15 additions & 42 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
}
@@ -189,13 +163,12 @@ void tagEntryArrayPush (struct tagEntryArray *a, tagEntry *e)
189163
{
190164
if (a->count + 1 == a->length)
191165
{
192-
if (a->length * 2 < a->length)
193-
perror("Too large array allocation");
194-
195-
struct tagEntryHolder *tmp = realloc (a->a, sizeof (a->a[0]) * (a->length * 2));
196-
if (!tmp)
197-
perror(__FUNCTION__);
166+
if (a->length * 2 < a->length) {
167+
fprintf(stderr, "too large array allocation");
168+
exit(1);
169+
}
198170

171+
struct tagEntryHolder *tmp = eRealloc (a->a, sizeof (a->a[0]) * (a->length * 2));
199172
a->a = tmp;
200173
a->length *= 2;
201174
}

0 commit comments

Comments
 (0)