summaryrefslogtreecommitdiff
path: root/rpmio/macro.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-09-27 09:33:35 +0300
committerPanu Matilainen <pmatilai@redhat.com>2010-09-27 14:55:11 +0300
commit8082eb48dbb9ab39826b5e1be9b764b0940a9a79 (patch)
tree17debc3ad0ae9f9e2ec9e33ab572171f8e26f274 /rpmio/macro.c
parentebc4ceaaeb8bb59019f4635471b28eb5f3eaaaa6 (diff)
downloadrpm-8082eb48dbb9ab39826b5e1be9b764b0940a9a79.tar.gz
rpm-8082eb48dbb9ab39826b5e1be9b764b0940a9a79.tar.bz2
rpm-8082eb48dbb9ab39826b5e1be9b764b0940a9a79.zip
Avoid calloc() in macro findEntry()
- It's just the macro name we're grabbing here, that ought to fit on stack comfortably enough.
Diffstat (limited to 'rpmio/macro.c')
-rw-r--r--rpmio/macro.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index 8b8ce592f..78d10099e 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -201,25 +201,24 @@ findEntry(rpmMacroContext mc, const char * name, size_t namelen)
{
rpmMacroEntry key, *ret;
struct rpmMacroEntry_s keybuf;
- char *namebuf = NULL;
+ char namebuf[namelen+1];
+ const char *mname = name;
if (mc == NULL) mc = rpmGlobalMacroContext;
if (mc->macroTable == NULL || mc->firstFree == 0)
return NULL;
if (namelen > 0) {
- namebuf = xcalloc(namelen + 1, sizeof(*namebuf));
strncpy(namebuf, name, namelen);
namebuf[namelen] = '\0';
- name = namebuf;
+ mname = namebuf;
}
key = &keybuf;
memset(key, 0, sizeof(*key));
- key->name = (char *)name;
+ key->name = (char *)mname;
ret = (rpmMacroEntry *) bsearch(&key, mc->macroTable, mc->firstFree,
sizeof(*(mc->macroTable)), compareMacroName);
- _free(namebuf);
/* XXX TODO: find 1st empty slot and return that */
return ret;
}