public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] elf: fix handling of negative numbers in dl-printf
@ 2023-05-25 17:10 Florian Weimer
  0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2023-05-25 17:10 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dae801527386f94e9d2fabf23c37863d1b599153

commit dae801527386f94e9d2fabf23c37863d1b599153
Author: Roy Eldar <royeldar0@gmail.com>
Date:   Thu May 25 17:41:58 2023 +0300

    elf: fix handling of negative numbers in dl-printf
    
    _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>
    Reviewed-by: Florian Weimer <fweimer@redhat.com>

Diff:
---
 elf/dl-printf.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/elf/dl-printf.c b/elf/dl-printf.c
index e8b9900370..6efb4c019a 100644
--- a/elf/dl-printf.c
+++ b/elf/dl-printf.c
@@ -1,5 +1,6 @@
 /* printf implementation for the dynamic loader.
    Copyright (C) 1997-2023 Free Software Foundation, Inc.
+   Copyright The GNU Toolchain Authors.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -150,19 +151,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
 		  }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-25 17:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25 17:10 [glibc] elf: fix handling of negative numbers in dl-printf 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).