public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] gimple-ssa-sprintf: Fix typo in range check
Date: Fri, 26 Jul 2024 13:39:04 -0400	[thread overview]
Message-ID: <862b3a6b-20c5-41dd-95c3-9fab2debd164@gotplt.org> (raw)
In-Reply-To: <ZqPYsl7ZsVZhNl9Q@tucnak>

On 2024-07-26 13:11, Jakub Jelinek wrote:
> On Thu, Jul 25, 2024 at 07:48:38PM -0400, Siddhesh Poyarekar wrote:
>> The code to scale ranges for wide chars in format_string incorrectly
>> checks range.likely to scale range.unlikely, which is a copy-paste typo
>> from the immediate previous condition.
>>
>> gcc/ChangeLog:
>>
>> 	gimple-ssa-sprintf.cc (format_string): Fix type in range check
>> 	for UNLIKELY for wide chars.
>>
>> Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
> 
> LGTM.

Thanks, pushed.

> What exactly the code really wants to do is unclear to me, what does
> the INT_MAX on the target have to do with the minimum/maximum/expected
> sizes of %S or %ls printed strings is unclear, target PTRDIFF_MAX

I think that is because the printf family returns the number of 
bytes/chars written in an int, which imposes the INT_MAX limitation on 
the format string expansion.

> maybe.  And why it uses this
> 	  if (slen.range.something < target_int_max ())
> 	    slen.range.something *= something_else;
> rather than say
> 	  slen.range.something
> 	    = MIN (slang.range.something * something_else, target_int_max ());
> perhaps with some overflow checking is also something that is hard to guess.

That's what I tried first but I settled for the minimal change because I 
didn't want to dig in deeper than I had time for to at the moment. 
Further down it checks if MAX and UNLIKELY cross INT_MAX and then resets 
to INT_MAX, but that looks suspicious on, e.g. 32-bit targets.  The code 
could use some refactoring/cleanup.

Thanks,
Sid

  reply	other threads:[~2024-07-26 17:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-25 23:48 Siddhesh Poyarekar
2024-07-26 17:11 ` Jakub Jelinek
2024-07-26 17:39   ` Siddhesh Poyarekar [this message]
2024-07-26 18:19     ` Jakub Jelinek

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=862b3a6b-20c5-41dd-95c3-9fab2debd164@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /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: link
Be 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).