public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: Mark Wielaard <mark@klomp.org>
Cc: <gcc-rust@gcc.gnu.org>
Subject: Re: [PATCH] Fix byte char and byte string lexing code
Date: Wed, 22 Sep 2021 11:48:56 +0200	[thread overview]
Message-ID: <87k0j9ym7r.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <20210921225430.166550-1-mark@klomp.org>

Hi Mark!

On 2021-09-22T00:54:30+0200, Mark Wielaard <mark@klomp.org> wrote:
> There were two warnings in lexer parse_byte_char and parse_byte_string
> code for arches with signed chars:
>
> rust-lex.cc: In member function
>              ‘Rust::TokenPtr Rust::Lexer::parse_byte_char(Location)’:
> rust-lex.cc:1564:21: warning: comparison is always false due to limited
>                      range of data type [-Wtype-limits]
>  1564 |       if (byte_char > 127)
>       |           ~~~~~~~~~~^~~~~

That's <https://github.com/Rust-GCC/gccrs/pull/343>.

> rust-lex.cc: In member function
>              ‘Rust::TokenPtr Rust::Lexer::parse_byte_string(Location)’:
> rust-lex.cc:1639:27: warning: comparison is always false due to limited
>                      range of data type [-Wtype-limits]
>  1639 |           if (output_char > 127)
>       |               ~~~~~~~~~~~~^~~~~

That's <https://github.com/Rust-GCC/gccrs/pull/344>.

Both these related to <https://github.com/Rust-GCC/gccrs/issues/336>
"GCC '--enable-bootstrap' build".

> The fix would be to cast to an unsigned char before the comparison.
> But that is actually wrong, and would produce the following errors
> parsing a byte char or byte string:
>
> bytecharstring.rs:3:14: error: ‘byte char’ ‘�’ out of range
>     3 |   let _bc = b'\x80';
>       |              ^
> bytecharstring.rs:4:14: error: character ‘�’ in byte string out of range
>     4 |   let _bs = b"foo\x80bar";
>       |              ^
>
> Both byte chars and byte strings may contain up to \xFF (255)
> characters. It is utf-8 chars or strings that can only [truncated here -- but I understand what you mean]

I think this does match my thoughts in
<https://github.com/Rust-GCC/gccrs/pull/343#issuecomment-816214689>.

> Remove the faulty check and add a new testcase bytecharstring.rs
> that checks byte chars and strings do accept > 127 hex char
> escapes, but utf-8 chars and strings reject such hex char escapes.
> ---
>
> https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=bytecharstring

Thanks, that's now: <https://github.com/Rust-GCC/gccrs/pull/687>
"Fix byte char and byte string lexing code".


Grüße
 Thomas
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

  reply	other threads:[~2021-09-22  9:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-21 22:54 Mark Wielaard
2021-09-22  9:48 ` Thomas Schwinge [this message]
2021-09-22 20:37   ` Mark Wielaard
2021-09-23 11:43     ` Philip Herron
2021-09-23 14:10       ` Arthur Cohen
2021-09-23 20:53         ` byte/char string representation (Was: [PATCH] Fix byte char and byte string lexing code) Mark Wielaard
2021-09-24 11:01           ` Philip Herron
2021-09-25 11:53             ` Mark Wielaard
2021-09-30 10:46               ` Philip Herron
2021-10-03 22:04                 ` Mark Wielaard

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=87k0j9ym7r.fsf@euler.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=gcc-rust@gcc.gnu.org \
    --cc=mark@klomp.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: 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).