summaryrefslogtreecommitdiff
path: root/elf/dl-exception.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-11-29 14:15:01 -0800
committerH.J. Lu <hjl.tools@gmail.com>2018-11-29 14:47:27 -0800
commita5275ba5378c9256d18e582572b4315e8edfcbfb (patch)
treee8466df5b9e62c25bd07df9d749e565022b59729 /elf/dl-exception.c
parent3a67e81d7527363a96af095a5af03b6201b82e9d (diff)
downloadglibc-a5275ba5378c9256d18e582572b4315e8edfcbfb.tar.gz
_dl_exception_create_format: Support %x/%lx/%zx
Add support for %x, %lx and %zx to _dl_exception_create_format and pad to the full width with 0. * elf/Makefile (tests-internal): Add tst-create_format1. * elf/dl-exception.c (_dl_exception_create_format): Support %x, %lx and %zx. * elf/tst-create_format1.c: New file.
Diffstat (limited to 'elf/dl-exception.c')
-rw-r--r--elf/dl-exception.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/elf/dl-exception.c b/elf/dl-exception.c
index 1c63e4a3a6..1e41d89a7d 100644
--- a/elf/dl-exception.c
+++ b/elf/dl-exception.c
@@ -111,6 +111,20 @@ _dl_exception_create_format (struct dl_exception *exception, const char *objname
case 's':
length += strlen (va_arg (ap, const char *));
break;
+ /* Recognize the l modifier. It is only important on some
+ platforms where long and int have a different size. We
+ can use the same code for size_t. */
+ case 'l':
+ case 'z':
+ if (p[1] == 'x')
+ {
+ length += LONG_WIDTH / 4;
+ ++p;
+ break;
+ }
+ case 'x':
+ length += INT_WIDTH / 4;
+ break;
default:
/* Assumed to be '%'. */
++length;
@@ -167,6 +181,32 @@ _dl_exception_create_format (struct dl_exception *exception, const char *objname
*wptr = '%';
++wptr;
break;
+ case 'x':
+ {
+ unsigned long int num = va_arg (ap, unsigned int);
+ char *start = wptr;
+ wptr += INT_WIDTH / 4;
+ char *cp = _itoa (num, wptr, 16, 0);
+ /* Pad to the full width with 0. */
+ while (cp != start)
+ *--cp = '0';
+ }
+ break;
+ case 'l':
+ case 'z':
+ if (p[1] == 'x')
+ {
+ unsigned long int num = va_arg (ap, unsigned long int);
+ char *start = wptr;
+ wptr += LONG_WIDTH / 4;
+ char *cp = _itoa (num, wptr, 16, 0);
+ /* Pad to the full width with 0. */
+ while (cp != start)
+ *--cp = '0';
+ ++p;
+ break;
+ }
+ /* FALLTHROUGH */
default:
_dl_fatal_printf ("Fatal error:"
" invalid format in exception string\n");