public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: fix handling of negative numbers in dl-printf
@ 2023-05-03 21:16 Roy Eldar
  2023-05-08 13:42 ` Florian Weimer
  2023-05-25  7:46 ` [PATCH] elf: fix handling of negative numbers in dl-printf Florian Weimer
  0 siblings, 2 replies; 11+ messages in thread
From: Roy Eldar @ 2023-05-03 21:16 UTC (permalink / raw)
  To: libc-alpha; +Cc: Roy Eldar, carlos

_dl_debug_vdprintf is a bare-bones printf implementation; currently
printing a signed integer (using "%d" format specifier) behaves
incorrectly when the number is negative, as it just prints the
corresponding unsigned integer, preceeded by a minus sign.

For example, _dl_printf("%d", -1) would print '-4294967295'.

Signed-off-by: Roy Eldar <royeldar0@gmail.com>
---
 elf/dl-printf.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/elf/dl-printf.c b/elf/dl-printf.c
index e8b9900370..977ac330b6 100644
--- a/elf/dl-printf.c
+++ b/elf/dl-printf.c
@@ -150,19 +150,25 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
 		    if (long_mod)
 		      {
 			if ((long int) num < 0)
-			  negative = true;
+			  {
+			    num = -num;
+			    negative = true;
+			  }
 		      }
 		    else
 		      {
 			if ((int) num < 0)
 			  {
-			    num = (unsigned int) num;
+			    num = -(unsigned int) num;
 			    negative = true;
 			  }
 		      }
 #else
 		    if ((int) num < 0)
-		      negative = true;
+		      {
+			num = -num;
+			negative = true;
+		      }
 #endif
 		  }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-05-25 17:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 21:16 [PATCH] elf: fix handling of negative numbers in dl-printf Roy Eldar
2023-05-08 13:42 ` Florian Weimer
2023-05-08 18:08   ` Roy E
2023-05-24 17:41     ` Roy E
2023-05-15 20:29   ` [PATCH] elf: add test for dl-printf Roy Eldar
2023-05-25  7:44     ` Florian Weimer
2023-05-25 14:41       ` [PATCH v2] " Roy Eldar
2023-05-25 17:10         ` Florian Weimer
2023-05-25  7:46 ` [PATCH] elf: fix handling of negative numbers in dl-printf Florian Weimer
2023-05-25 14:41   ` [PATCH v2] " Roy Eldar
2023-05-25 17:10     ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).