9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9fans@9fans.net
Subject: Re: [9fans] a strange bug in grep
Date: Sun, 30 Mar 2014 20:05:27 +0200	[thread overview]
Message-ID: <7cfbee84ff7ffe431e0974e4281cb0e5@felloff.net> (raw)
In-Reply-To: <47ce4a1e83ccab956e28cc2b42fe2ba6@brasstown.quanstro.net>

no.

lets try example with p1=0x3ffff and p2=0x7ffff and assuming your m=0x7ffff mask
in tab2.

p1 (0x3ffff) = 0xf0 0xbf 0xbf 0xbf (0b11110000 0b10111111 0b10111111 0b10111111)
p2 (0x7ffff) = 0xf1 0xbf 0xbf 0xbf (0b11110001 0b10111111 0b10111111 0b10111111)

for m == 0x7ffff

(p1 & ~m) == 0
(p2 & ~m) == 0

if((p1 & ~m) != (p2 & ~m)) {
	... bust
}

so this if case is never taken, tho the lead byte in the utf8 encoding is different
for this p1-p2 range and the following encoded bytes are not comparable.

> 0xxxxxxx
> 110xxxxx 10mmmmmm
0x3f -> 6 bits (count m's)

> 1110xxxx 10mmmmmm 10mmmmmm
0xfff -> 12 bits (count m's)

> 11110xxx 10mmmmmm 10mmmmmm 10mmmmmm
0x3ffff -> 18 bits (count m's)

repeat example with 18 bit mask m=0x3ffff we get (p2 & ~m) == 0x40000 then
we bust and following encoded bytes are compared in each branch separately.

--
cinap



  reply	other threads:[~2014-03-30 18:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-29 23:31 arisawa
2014-03-29 23:54 ` erik quanstrom
2014-03-30  0:51   ` arisawa
2014-03-30  1:44   ` cinap_lenrek
2014-03-30  6:10     ` erik quanstrom
2014-03-30 15:40       ` cinap_lenrek
2014-03-30 16:26         ` erik quanstrom
2014-03-30 18:05           ` cinap_lenrek [this message]
2014-03-30 18:10             ` erik quanstrom
2014-03-30  6:24     ` erik quanstrom

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=7cfbee84ff7ffe431e0974e4281cb0e5@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9fans@9fans.net \
    /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 NNTP newsgroup(s).