public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Florian Weimer <fw@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] elf: fix handling of negative numbers in dl-printf Date: Thu, 25 May 2023 17:10:01 +0000 (GMT) [thread overview] Message-ID: <20230525171001.876443857715@sourceware.org> (raw) 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 }
reply other threads:[~2023-05-25 17:10 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230525171001.876443857715@sourceware.org \ --to=fw@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).