From ffa082ba1f9a224e50b9b36acbf9c8b4d401c38c Mon Sep 17 00:00:00 2001
From: jimb <jimb@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 15 May 2003 19:02:13 +0000
Subject: [PATCH] libiberty/ChangeLog: 2003-05-14  Jim Blandy 
 <jimb@redhat.com>

	* hex.c (_hex_value): Make this unsigned.
	(hex_value): Update documentation for new return type.  hex_value
	now expands to an unsigned int expression, to avoid unexpected
	sign extension when we store it in a bfd_vma, which is larger than
	int on some platforms.
	* functions.texi: Regenerated.

include/ChangeLog:
2003-05-14  Jim Blandy  <jimb@redhat.com>

	* libiberty.h (hex_value): Make the value an unsigned int, to
	avoid unexpected sign-extension when cast to unsigned types larger
	than int --- like bfd_vma, on some platforms.
	(_hex_value): Update declaration.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66840 138bc75d-0d04-0410-961f-82ee72b054a4
---
 include/ChangeLog        |  7 +++++++
 include/libiberty.h      |  4 ++--
 libiberty/ChangeLog      |  9 +++++++++
 libiberty/functions.texi |  8 +++++++-
 libiberty/hex.c          | 12 +++++++++---
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/include/ChangeLog b/include/ChangeLog
index e4aad2ba993b..c7c271b1ca95 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,10 @@
+2003-05-15  Jim Blandy  <jimb@redhat.com>
+
+	* libiberty.h (hex_value): Make the value an unsigned int, to
+	avoid unexpected sign-extension when cast to unsigned types larger
+	than int --- like bfd_vma, on some platforms.
+	(_hex_value): Update declaration.
+
 2003-05-07  Jason Merrill  <jason@redhat.com>
 
 	* hashtab.h (iterative_hash): Prototype.
diff --git a/include/libiberty.h b/include/libiberty.h
index 676ceaba4a9c..761b2cf060ff 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -254,12 +254,12 @@ extern double physmem_available PARAMS ((void));
 
 #define _hex_array_size 256
 #define _hex_bad	99
-extern const char _hex_value[_hex_array_size];
+extern const unsigned char _hex_value[_hex_array_size];
 extern void hex_init PARAMS ((void));
 #define hex_p(c)	(hex_value (c) != _hex_bad)
 /* If you change this, note well: Some code relies on side effects in
    the argument being performed exactly once.  */
-#define hex_value(c)	(_hex_value[(unsigned char) (c)])
+#define hex_value(c)	((unsigned int) _hex_value[(unsigned char) (c)])
 
 /* Definitions used by the pexecute routine.  */
 
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 066980339bac..d30c591d2472 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,12 @@
+2003-05-15  Jim Blandy  <jimb@redhat.com>
+
+	* hex.c (_hex_value): Make this unsigned.
+	(hex_value): Update documentation for new return type.  hex_value
+	now expands to an unsigned int expression, to avoid unexpected
+	sign extension when we store it in a bfd_vma, which is larger than
+	int on some platforms.
+	* functions.texi: Regenerated.
+
 2003-05-07  Josef Zlomek  <zlomekj@suse.cz>
 
 	* splay-tree.c (splay_tree_predecessor): Fix comment.
diff --git a/libiberty/functions.texi b/libiberty/functions.texi
index 4261d8646761..b34c20409e31 100644
--- a/libiberty/functions.texi
+++ b/libiberty/functions.texi
@@ -337,13 +337,19 @@ or zero if it is not.  Note that the value you pass will be cast to
 @end deftypefn
 
 @c hex.c:42
-@deftypefn Extension int hex_value (int @var{c})
+@deftypefn Extension unsigned int hex_value (int @var{c})
 
 Returns the numeric equivalent of the given character when interpreted
 as a hexidecimal digit.  The result is undefined if you pass an
 invalid hex digit.  Note that the value you pass will be cast to
 @code{unsigned char} within the macro.
 
+The @code{hex_value} macro returns @code{unsigned int}, rather than
+signed @code{int}, to make it easier to use in parsing addresses from
+hex dump files: a signed @code{int} would be sign-extended when
+converted to a wider unsigned type --- like @code{bfd_vma}, on some
+systems.
+
 @end deftypefn
 
 @c index.c:5
diff --git a/libiberty/hex.c b/libiberty/hex.c
index 5f8229253494..f425509be75c 100644
--- a/libiberty/hex.c
+++ b/libiberty/hex.c
@@ -39,13 +39,19 @@ or zero if it is not.  Note that the value you pass will be cast to
 
 @end deftypefn
 
-@deftypefn Extension int hex_value (int @var{c})
+@deftypefn Extension unsigned int hex_value (int @var{c})
 
 Returns the numeric equivalent of the given character when interpreted
 as a hexidecimal digit.  The result is undefined if you pass an
 invalid hex digit.  Note that the value you pass will be cast to
 @code{unsigned char} within the macro.
 
+The @code{hex_value} macro returns @code{unsigned int}, rather than
+signed @code{int}, to make it easier to use in parsing addresses from
+hex dump files: a signed @code{int} would be sign-extended when
+converted to a wider unsigned type --- like @code{bfd_vma}, on some
+systems.
+
 @end deftypefn
 
 @undocumented _hex_array_size
@@ -60,7 +66,7 @@ invalid hex digit.  Note that the value you pass will be cast to
   && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
   && EOF == -1
 
-const char _hex_value[_hex_array_size] =
+const unsigned char _hex_value[_hex_array_size] =
 {
   _hex_bad, _hex_bad, _hex_bad, _hex_bad,   /* NUL SOH STX ETX */
   _hex_bad, _hex_bad, _hex_bad, _hex_bad,   /* EOT ENQ ACK BEL */
@@ -139,7 +145,7 @@ const char _hex_value[_hex_array_size] =
 
 #else
 
-char _hex_value[_hex_array_size];
+unsigned char _hex_value[_hex_array_size];
 
 #endif /* not ASCII */
 
-- 
GitLab