mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-04 12:52:15 +00:00
libelftc: Consistently use size_t for string table offsets and sizes.
Reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D20702
This commit is contained in:
parent
70b0aff9a1
commit
b90eaf941f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349421
contrib/elftoolchain/libelftc
@ -44,7 +44,7 @@ ELFTC_VCSID("$Id: elftc_string_table.c 2869 2013-01-06 13:29:18Z jkoshy $");
|
||||
#define ELFTC_STRING_TABLE_POOL_SIZE_INCREMENT (4*1024)
|
||||
|
||||
struct _Elftc_String_Table_Entry {
|
||||
int ste_idx;
|
||||
ssize_t ste_idx;
|
||||
SLIST_ENTRY(_Elftc_String_Table_Entry) ste_next;
|
||||
};
|
||||
|
||||
@ -64,9 +64,9 @@ struct _Elftc_String_Table_Entry {
|
||||
} while (0)
|
||||
|
||||
struct _Elftc_String_Table {
|
||||
unsigned int st_len; /* length and flags */
|
||||
size_t st_len; /* length and flags */
|
||||
int st_nbuckets;
|
||||
int st_string_pool_size;
|
||||
size_t st_string_pool_size;
|
||||
char *st_string_pool;
|
||||
SLIST_HEAD(_Elftc_String_Table_Bucket,
|
||||
_Elftc_String_Table_Entry) st_buckets[];
|
||||
@ -86,7 +86,7 @@ elftc_string_table_find_hash_entry(Elftc_String_Table *st, const char *string,
|
||||
*rhashindex = hashindex;
|
||||
|
||||
SLIST_FOREACH(ste, &st->st_buckets[hashindex], ste_next) {
|
||||
s = st->st_string_pool + abs(ste->ste_idx);
|
||||
s = st->st_string_pool + labs(ste->ste_idx);
|
||||
|
||||
assert(s > st->st_string_pool &&
|
||||
s < st->st_string_pool + st->st_string_pool_size);
|
||||
@ -102,7 +102,7 @@ static int
|
||||
elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string)
|
||||
{
|
||||
char *newpool;
|
||||
int len, newsize, stlen;
|
||||
size_t len, newsize, stlen;
|
||||
|
||||
len = strlen(string) + 1; /* length, including the trailing NUL */
|
||||
stlen = ELFTC_STRING_TABLE_LENGTH(st);
|
||||
@ -126,10 +126,10 @@ elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string)
|
||||
}
|
||||
|
||||
Elftc_String_Table *
|
||||
elftc_string_table_create(int sizehint)
|
||||
elftc_string_table_create(size_t sizehint)
|
||||
{
|
||||
int n, nbuckets, tablesize;
|
||||
struct _Elftc_String_Table *st;
|
||||
int n, nbuckets, tablesize;
|
||||
|
||||
if (sizehint < ELFTC_STRING_TABLE_DEFAULT_SIZE)
|
||||
sizehint = ELFTC_STRING_TABLE_DEFAULT_SIZE;
|
||||
@ -173,13 +173,13 @@ elftc_string_table_destroy(Elftc_String_Table *st)
|
||||
}
|
||||
|
||||
Elftc_String_Table *
|
||||
elftc_string_table_from_section(Elf_Scn *scn, int sizehint)
|
||||
elftc_string_table_from_section(Elf_Scn *scn, size_t sizehint)
|
||||
{
|
||||
int len;
|
||||
Elf_Data *d;
|
||||
GElf_Shdr sh;
|
||||
const char *s, *end;
|
||||
Elftc_String_Table *st;
|
||||
size_t len;
|
||||
|
||||
/* Verify the type of the section passed in. */
|
||||
if (gelf_getshdr(scn, &sh) == NULL ||
|
||||
@ -235,7 +235,8 @@ elftc_string_table_image(Elftc_String_Table *st, size_t *size)
|
||||
char *r, *s, *end;
|
||||
struct _Elftc_String_Table_Entry *ste;
|
||||
struct _Elftc_String_Table_Bucket *head;
|
||||
int copied, hashindex, offset, length, newsize;
|
||||
size_t copied, offset, length, newsize;
|
||||
int hashindex;
|
||||
|
||||
/*
|
||||
* For the common case of a string table has not seen
|
||||
@ -303,8 +304,9 @@ elftc_string_table_image(Elftc_String_Table *st, size_t *size)
|
||||
size_t
|
||||
elftc_string_table_insert(Elftc_String_Table *st, const char *string)
|
||||
{
|
||||
int hashindex, idx;
|
||||
struct _Elftc_String_Table_Entry *ste;
|
||||
ssize_t idx;
|
||||
int hashindex;
|
||||
|
||||
hashindex = 0;
|
||||
|
||||
@ -326,7 +328,7 @@ elftc_string_table_insert(Elftc_String_Table *st, const char *string)
|
||||
|
||||
idx = ste->ste_idx;
|
||||
if (idx < 0) /* Undelete. */
|
||||
ste->ste_idx = idx = (- idx);
|
||||
ste->ste_idx = idx = -idx;
|
||||
|
||||
return (idx);
|
||||
}
|
||||
@ -334,8 +336,9 @@ elftc_string_table_insert(Elftc_String_Table *st, const char *string)
|
||||
size_t
|
||||
elftc_string_table_lookup(Elftc_String_Table *st, const char *string)
|
||||
{
|
||||
int hashindex, idx;
|
||||
struct _Elftc_String_Table_Entry *ste;
|
||||
ssize_t idx;
|
||||
int hashindex;
|
||||
|
||||
ste = elftc_string_table_find_hash_entry(st, string, &hashindex);
|
||||
|
||||
@ -350,17 +353,17 @@ elftc_string_table_lookup(Elftc_String_Table *st, const char *string)
|
||||
int
|
||||
elftc_string_table_remove(Elftc_String_Table *st, const char *string)
|
||||
{
|
||||
int idx;
|
||||
struct _Elftc_String_Table_Entry *ste;
|
||||
ssize_t idx;
|
||||
|
||||
ste = elftc_string_table_find_hash_entry(st, string, NULL);
|
||||
|
||||
if (ste == NULL || (idx = ste->ste_idx) < 0)
|
||||
return (ELFTC_FAILURE);
|
||||
|
||||
assert(idx > 0 && idx < (int) ELFTC_STRING_TABLE_LENGTH(st));
|
||||
assert(idx > 0 && (size_t)idx < ELFTC_STRING_TABLE_LENGTH(st));
|
||||
|
||||
ste->ste_idx = (- idx);
|
||||
ste->ste_idx = -idx;
|
||||
|
||||
ELFTC_STRING_TABLE_SET_COMPACTION_FLAG(st);
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
.\"
|
||||
.\" $Id: elftc_string_table_create.3 3645 2018-10-15 20:17:14Z jkoshy $
|
||||
.\"
|
||||
.Dd January 5, 2013
|
||||
.Dd June 19, 2019
|
||||
.Dt ELFTC_STRING_TABLE_CREATE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -40,11 +40,11 @@
|
||||
.Sh SYNOPSIS
|
||||
.In libelftc.h
|
||||
.Ft "Elftc_String_Table *"
|
||||
.Fn elftc_string_table_create "int sizehint"
|
||||
.Fn elftc_string_table_create "size_t sizehint"
|
||||
.Ft int
|
||||
.Fn elftc_string_table_destroy "Elftc_String_Table *table"
|
||||
.Ft "Elftc_String_Table *"
|
||||
.Fn elftc_string_table_from_section "Elf_Scn *scn" "int sizehint"
|
||||
.Fn elftc_string_table_from_section "Elf_Scn *scn" "size_t sizehint"
|
||||
.Ft "const char *"
|
||||
.Fo elftc_string_table_image
|
||||
.Fa "Elftc_String_Table *table"
|
||||
|
@ -77,10 +77,10 @@ int elftc_demangle(const char *_mangledname, char *_buffer,
|
||||
size_t _bufsize, unsigned int _flags);
|
||||
const char *elftc_reloc_type_str(unsigned int mach, unsigned int type);
|
||||
int elftc_set_timestamps(const char *_filename, struct stat *_sb);
|
||||
Elftc_String_Table *elftc_string_table_create(int _hint);
|
||||
Elftc_String_Table *elftc_string_table_create(size_t _sizehint);
|
||||
void elftc_string_table_destroy(Elftc_String_Table *_table);
|
||||
Elftc_String_Table *elftc_string_table_from_section(Elf_Scn *_scn,
|
||||
int _hint);
|
||||
size_t _sizehint);
|
||||
const char *elftc_string_table_image(Elftc_String_Table *_table,
|
||||
size_t *_sz);
|
||||
size_t elftc_string_table_insert(Elftc_String_Table *_table,
|
||||
|
Loading…
Reference in New Issue
Block a user