This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support %Lx, %Lu, %Ld in _bfd_error_handler format


On Thu, Jul 6, 2017 at 7:36 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Jul 6, 2017 at 7:27 AM, Alan Modra <amodra@gmail.com> wrote:
>> On Thu, Jul 06, 2017 at 06:50:18AM -0700, H.J. Lu wrote:
>>> This is incomplete and breaks 32-bit bfd_vma.  I am checking in
>>>
>>> diff --git a/bfd/bfd.c b/bfd/bfd.c
>>> index b6cdf3f..a119ac4 100644
>>> --- a/bfd/bfd.c
>>> +++ b/bfd/bfd.c
>>> @@ -727,7 +727,10 @@ _doprnt (FILE *stream, const char *format, va_list ap)
>>>              either long long or long.  */
>>>           if ((BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
>>>          && sptr[-2] == 'L')
>>> -           wide_width = 1;
>>> +           {
>>> +        wide_width = 1;
>>> +        sptr[-2] = 'l';
>>> +           }
>>>
>>>           switch (wide_width)
>>>
>>> to fix it.
>>
>> Thanks.  Hmm, maybe "L" should be changed to "ll" for long long too.
>
> On Linux, L == l:
>
>  L      A following a, A, e, E, f, F, g, or G conversion corresponds  to
>               a  long  double argument.  (C99 allows %LF, but SUSv2 does not.)
>               This is a synonym for ll.
>
>

I backported it to 2.29 branch.


-- 
H.J.
From 9366af329bf6bdaa305579393fc0c39ca60d4455 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 6 Jul 2017 06:52:13 -0700
Subject: [PATCH] Convert 'L' to 'l' when setting wide_width to 1

When setting wide_width to 1, convert 'L' to 'l'.  Otherwise, %Lx/%Lu/%Ld
will be passed to fprintf which will treat the argument as long long.

	* bfd.c (_doprnt): Convert 'L' to 'l' when setting wide_width
	to 1.

(cherry picked from commit a0b7b105236d5bc65e8d3a35f1b4f34bcc5e3705)
---
 bfd/ChangeLog | 5 +++++
 bfd/bfd.c     | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f32b38e..1cb9969 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* bfd.c (_doprnt): Convert 'L' to 'l' when setting wide_width
+	to 1.
+
 2017-07-05  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* dwarf2.c (line_info_add_include_dir_stub): Replace time with
diff --git a/bfd/bfd.c b/bfd/bfd.c
index b6cdf3f..a119ac4 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -727,7 +727,10 @@ _doprnt (FILE *stream, const char *format, va_list ap)
 		       either long long or long.  */
 		    if ((BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
 			&& sptr[-2] == 'L')
-		      wide_width = 1;
+		      {
+			wide_width = 1;
+			sptr[-2] = 'l';
+		      }
 
 		    switch (wide_width)
 		      {
-- 
2.9.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]