9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Bgetrune while(i>runesize) loop
@ 2008-07-10 18:13 Pietro Gagliardi
  2008-07-10 18:53 ` Russ Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Pietro Gagliardi @ 2008-07-10 18:13 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello. I was looking at the code for the Bgetrune function trying to
implement a readrune() around read(). It works, but without a
counterpart for this:

		while(i > bp->runesize) {
			Bungetc(bp);
			i--;
		}

What is the point of that loop? Thanks.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] Bgetrune while(i>runesize) loop
  2008-07-10 18:13 [9fans] Bgetrune while(i>runesize) loop Pietro Gagliardi
@ 2008-07-10 18:53 ` Russ Cox
  2008-07-10 20:18   ` Pietro Gagliardi
  0 siblings, 1 reply; 4+ messages in thread
From: Russ Cox @ 2008-07-10 18:53 UTC (permalink / raw)
  To: 9fans

> Hello. I was looking at the code for the Bgetrune function trying to
> implement a readrune() around read(). It works, but without a
> counterpart for this:
>
> 		while(i > bp->runesize) {
> 			Bungetc(bp);
> 			i--;
> 		}
>
> What is the point of that loop? Thanks.

Use "\xE0\x00\x00" as your input and you will find out.

Russ



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] Bgetrune while(i>runesize) loop
  2008-07-10 18:53 ` Russ Cox
@ 2008-07-10 20:18   ` Pietro Gagliardi
  2008-07-10 20:45     ` Russ Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Pietro Gagliardi @ 2008-07-10 20:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I got nothing spectacular from that, but changing the \x00s to QRS
gave me something interesting: without the loop, readrune gives me
[?]S, but with it it, it gives me [?]QRS, like cat would've.

Would this be because fullrune doesn't check for validity, and if
chartorune fails then the possibility of eating too much comes about?

On Jul 10, 2008, at 2:53 PM, Russ Cox wrote:

>> Hello. I was looking at the code for the Bgetrune function trying to
>> implement a readrune() around read(). It works, but without a
>> counterpart for this:
>>
>> 		while(i > bp->runesize) {
>> 			Bungetc(bp);
>> 			i--;
>> 		}
>>
>> What is the point of that loop? Thanks.
>
> Use "\xE0\x00\x00" as your input and you will find out.
>
> Russ
>
>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] Bgetrune while(i>runesize) loop
  2008-07-10 20:18   ` Pietro Gagliardi
@ 2008-07-10 20:45     ` Russ Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Russ Cox @ 2008-07-10 20:45 UTC (permalink / raw)
  To: 9fans

> Would this be because fullrune doesn't check for validity, and if
> chartorune fails then the possibility of eating too much comes about?

Mostly, yes.  The fundamental issue is that, presented
with malformed UTF-8, chartorune needs to look at
more bytes than the number it returns.

Russ



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-10 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-10 18:13 [9fans] Bgetrune while(i>runesize) loop Pietro Gagliardi
2008-07-10 18:53 ` Russ Cox
2008-07-10 20:18   ` Pietro Gagliardi
2008-07-10 20:45     ` Russ Cox

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).