aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-misc.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-06-09 12:15:01 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-06-09 12:15:01 -0700
commit533dd2acf7eefa969fb770fa782b20519bd4bc0f (patch)
tree237c7fc72337308e806881ff4fd58d5568006b64 /elf/dl-misc.c
parenta365ac45b7b51dbd9dc65629203cc2a9603420bb (diff)
downloadglibc-533dd2acf7eefa969fb770fa782b20519bd4bc0f.zip
glibc-533dd2acf7eefa969fb770fa782b20519bd4bc0f.tar.gz
glibc-533dd2acf7eefa969fb770fa782b20519bd4bc0f.tar.bz2
Add "%d" support to _dl_debug_vdprintf
"%d" will be used to print out signed value.
Diffstat (limited to 'elf/dl-misc.c')
-rw-r--r--elf/dl-misc.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
index ab70481..f9d1fd7 100644
--- a/elf/dl-misc.c
+++ b/elf/dl-misc.c
@@ -167,6 +167,7 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
switch (*fmt)
{
/* Integer formatting. */
+ case 'd':
case 'u':
case 'x':
{
@@ -179,11 +180,34 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
#else
unsigned long int num = va_arg (arg, unsigned int);
#endif
+ bool negative = false;
+ if (*fmt == 'd')
+ {
+#if LONG_MAX != INT_MAX
+ if (long_mod)
+ {
+ if ((long int) num < 0)
+ negative = true;
+ }
+ else
+ {
+ if ((int) num < 0)
+ {
+ num = (unsigned int) num;
+ negative = true;
+ }
+ }
+#else
+ if ((int) num < 0)
+ negative = true;
+#endif
+ }
+
/* We use alloca() to allocate the buffer with the most
pessimistic guess for the size. Using alloca() allows
having more than one integer formatting in a call. */
- char *buf = (char *) alloca (3 * sizeof (unsigned long int));
- char *endp = &buf[3 * sizeof (unsigned long int)];
+ char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
+ char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
/* Pad to the width the user specified. */
@@ -191,6 +215,9 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
while (endp - cp < width)
*--cp = fill;
+ if (negative)
+ *--cp = '-';
+
iov[niov].iov_base = cp;
iov[niov].iov_len = endp - cp;
++niov;