summaryrefslogtreecommitdiff
path: root/elfutils/libebl/eblstrtab.c
diff options
context:
space:
mode:
Diffstat (limited to 'elfutils/libebl/eblstrtab.c')
-rw-r--r--elfutils/libebl/eblstrtab.c56
1 files changed, 20 insertions, 36 deletions
diff --git a/elfutils/libebl/eblstrtab.c b/elfutils/libebl/eblstrtab.c
index bbf0d6ee..165909f4 100644
--- a/elfutils/libebl/eblstrtab.c
+++ b/elfutils/libebl/eblstrtab.c
@@ -1,5 +1,5 @@
/* ELF string table handling.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000, 2001, 2002, 2005 Red Hat, Inc.
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
This program is Open Source software; you can redistribute it and/or
@@ -73,15 +73,14 @@ static size_t ps;
struct Ebl_Strtab *
ebl_strtabinit (bool nullstr)
{
- struct Ebl_Strtab *ret;
-
if (ps == 0)
{
ps = sysconf (_SC_PAGESIZE) - 2 * sizeof (void *);
assert (sizeof (struct memoryblock) < ps);
}
- ret = (struct Ebl_Strtab *) calloc (1, sizeof (struct Ebl_Strtab));
+ struct Ebl_Strtab *ret
+ = (struct Ebl_Strtab *) calloc (1, sizeof (struct Ebl_Strtab));
if (ret != NULL)
{
ret->nullstr = nullstr;
@@ -100,11 +99,10 @@ ebl_strtabinit (bool nullstr)
static int
morememory (struct Ebl_Strtab *st, size_t len)
{
- struct memoryblock *newmem;
-
if (len < ps)
len = ps;
- newmem = (struct memoryblock *) malloc (len);
+
+ struct memoryblock *newmem = (struct memoryblock *) malloc (len);
if (newmem == NULL)
return 1;
@@ -136,15 +134,11 @@ ebl_strtabfree (struct Ebl_Strtab *st)
static struct Ebl_Strent *
newstring (struct Ebl_Strtab *st, const char *str, size_t len)
{
- struct Ebl_Strent *newstr;
- size_t align;
- int i;
-
/* Compute the amount of padding needed to make the structure aligned. */
- align = ((__alignof__ (struct Ebl_Strent)
- - (((uintptr_t) st->backp)
- & (__alignof__ (struct Ebl_Strent) - 1)))
- & (__alignof__ (struct Ebl_Strent) - 1));
+ size_t align = ((__alignof__ (struct Ebl_Strent)
+ - (((uintptr_t) st->backp)
+ & (__alignof__ (struct Ebl_Strent) - 1)))
+ & (__alignof__ (struct Ebl_Strent) - 1));
/* Make sure there is enough room in the memory block. */
if (st->left < align + sizeof (struct Ebl_Strent) + len)
@@ -156,14 +150,14 @@ newstring (struct Ebl_Strtab *st, const char *str, size_t len)
}
/* Create the reserved string. */
- newstr = (struct Ebl_Strent *) (st->backp + align);
+ struct Ebl_Strent *newstr = (struct Ebl_Strent *) (st->backp + align);
newstr->string = str;
newstr->len = len;
newstr->next = NULL;
newstr->left = NULL;
newstr->right = NULL;
newstr->offset = 0;
- for (i = len - 2; i >= 0; --i)
+ for (int i = len - 2; i >= 0; --i)
newstr->reverse[i] = str[len - 2 - i];
newstr->reverse[len - 1] = '\0';
st->backp += align + sizeof (struct Ebl_Strent) + len;
@@ -179,8 +173,6 @@ newstring (struct Ebl_Strtab *st, const char *str, size_t len)
static struct Ebl_Strent **
searchstring (struct Ebl_Strent **sep, struct Ebl_Strent *newstr)
{
- int cmpres;
-
/* More strings? */
if (*sep == NULL)
{
@@ -189,8 +181,8 @@ searchstring (struct Ebl_Strent **sep, struct Ebl_Strent *newstr)
}
/* Compare the strings. */
- cmpres = memcmp ((*sep)->reverse, newstr->reverse,
- MIN ((*sep)->len, newstr->len) - 1);
+ int cmpres = memcmp ((*sep)->reverse, newstr->reverse,
+ MIN ((*sep)->len, newstr->len) - 1);
if (cmpres == 0)
/* We found a matching string. */
return sep;
@@ -205,9 +197,6 @@ searchstring (struct Ebl_Strent **sep, struct Ebl_Strent *newstr)
struct Ebl_Strent *
ebl_strtabadd (struct Ebl_Strtab *st, const char *str, size_t len)
{
- struct Ebl_Strent *newstr;
- struct Ebl_Strent **sep;
-
/* Compute the string length if the caller doesn't know it. */
if (len == 0)
len = strlen (str) + 1;
@@ -218,23 +207,22 @@ ebl_strtabadd (struct Ebl_Strtab *st, const char *str, size_t len)
return &st->null;
/* Allocate memory for the new string and its associated information. */
- newstr = newstring (st, str, len);
+ struct Ebl_Strent *newstr = newstring (st, str, len);
if (newstr == NULL)
return NULL;
/* Search in the array for the place to insert the string. If there
is no string with matching prefix and no string with matching
leading substring, create a new entry. */
- sep = searchstring (&st->root, newstr);
+ struct Ebl_Strent **sep = searchstring (&st->root, newstr);
if (*sep != newstr)
{
/* This is not the same entry. This means we have a prefix match. */
if ((*sep)->len > newstr->len)
{
- struct Ebl_Strent *subs;
-
/* Check whether we already know this string. */
- for (subs = (*sep)->next; subs != NULL; subs = subs->next)
+ for (struct Ebl_Strent *subs = (*sep)->next; subs != NULL;
+ subs = subs->next)
if (subs->len == newstr->len)
{
/* We have an exact match with a substring. Free the memory
@@ -283,8 +271,6 @@ ebl_strtabadd (struct Ebl_Strtab *st, const char *str, size_t len)
static void
copystrings (struct Ebl_Strent *nodep, char **freep, size_t *offsetp)
{
- struct Ebl_Strent *subs;
-
if (nodep->left != NULL)
copystrings (nodep->left, freep, offsetp);
@@ -293,7 +279,7 @@ copystrings (struct Ebl_Strent *nodep, char **freep, size_t *offsetp)
*freep = (char *) mempcpy (*freep, nodep->string, nodep->len);
*offsetp += nodep->len;
- for (subs = nodep->next; subs != NULL; subs = subs->next)
+ for (struct Ebl_Strent *subs = nodep->next; subs != NULL; subs = subs->next)
{
assert (subs->len < nodep->len);
subs->offset = nodep->offset + nodep->len - subs->len;
@@ -308,8 +294,6 @@ copystrings (struct Ebl_Strent *nodep, char **freep, size_t *offsetp)
void
ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data)
{
- size_t copylen;
- char *endp;
size_t nulllen = st->nullstr ? 1 : 0;
/* Fill in the information. */
@@ -330,8 +314,8 @@ ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data)
/* Now run through the tree and add all the string while also updating
the offset members of the elfstrent records. */
- endp = (char *) data->d_buf + nulllen;
- copylen = nulllen;
+ char *endp = (char *) data->d_buf + nulllen;
+ size_t copylen = nulllen;
copystrings (st->root, &endp, &copylen);
assert (copylen == st->total + nulllen);
}