Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jun 2019 16:31:51 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r349421 - head/contrib/elftoolchain/libelftc
Message-ID:  <201906261631.x5QGVp2i047833@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Wed Jun 26 16:31:50 2019
New Revision: 349421
URL: https://svnweb.freebsd.org/changeset/base/349421

Log:
  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

Modified:
  head/contrib/elftoolchain/libelftc/elftc_string_table.c
  head/contrib/elftoolchain/libelftc/elftc_string_table_create.3
  head/contrib/elftoolchain/libelftc/libelftc.h

Modified: head/contrib/elftoolchain/libelftc/elftc_string_table.c
==============================================================================
--- head/contrib/elftoolchain/libelftc/elftc_string_table.c	Wed Jun 26 16:30:14 2019	(r349420)
+++ head/contrib/elftoolchain/libelftc/elftc_string_table.c	Wed Jun 26 16:31:50 2019	(r349421)
@@ -44,7 +44,7 @@ ELFTC_VCSID("$Id: elftc_string_table.c 2869 2013-01-06
 #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 
 		*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,
 }
 
 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_
 	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_
 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, cons
 
 	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, cons
 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, cons
 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);
 

Modified: head/contrib/elftoolchain/libelftc/elftc_string_table_create.3
==============================================================================
--- head/contrib/elftoolchain/libelftc/elftc_string_table_create.3	Wed Jun 26 16:30:14 2019	(r349420)
+++ head/contrib/elftoolchain/libelftc/elftc_string_table_create.3	Wed Jun 26 16:31:50 2019	(r349421)
@@ -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"

Modified: head/contrib/elftoolchain/libelftc/libelftc.h
==============================================================================
--- head/contrib/elftoolchain/libelftc/libelftc.h	Wed Jun 26 16:30:14 2019	(r349420)
+++ head/contrib/elftoolchain/libelftc/libelftc.h	Wed Jun 26 16:31:50 2019	(r349421)
@@ -77,10 +77,10 @@ int		elftc_demangle(const char *_mangledname, char *_b
     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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906261631.x5QGVp2i047833>