New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in read() #7491
Comments
From chris@heathens.co.nzHi, I just found a rather obscure bug in read(). It is scanning over Here's my test case: echo A | perl -e '$c=chr(256).chr(32).chr(255);$c=chr(256); Output is: Output should be: It only happens when $c (the second parameter to read()) is a UTF8 My Perl version is: but from looking at the source code, it looks like the bug is still Chris |
From chris@heathens.co.nzHere is a patch for this bug. HTH, Inline Patch--- pp_sys.c.orig 2004-09-05 22:54:59.000000000 -0400
+++ pp_sys.c 2004-09-05 23:00:37.000000000 -0400
@@ -1656,7 +1656,10 @@
}
if (DO_UTF8(bufsv)) {
/* convert offset-as-chars to offset-as-bytes */
- offset = utf8_hop((U8 *)buffer,offset) - (U8 *) buffer;
+ if (offset >= (int)blen)
+ offset += SvCUR(bufsv) - blen;
+ else
+ offset = utf8_hop((U8 *)buffer,offset) - (U8 *) buffer;
}
more_bytes:
bufsize = SvCUR(bufsv); |
From @iabynOn Mon, Sep 06, 2004 at 12:03:12AM -0400, Chris Heath wrote:
Well-spotted!
Thanks, applied to the development branch of Perl as change #23321 P5Pers: while looking at this bug, I noticed that a read from a $ echo 'B'|./perl -Ilib -MDevel::Peek -e'$c="\x{100}A";Dump($c);read STDIN,$c,1,1;Dump($c)' Ideally I'd expect the resulting string to be "\x{100}B" rather than -- |
The RT System itself - Status changed from 'new' to 'open' |
From chris@heathens.co.nzOn Tue, 2004-09-14 at 18:18, Dave Mitchell via RT wrote:
You have a good point. I would be happy to take a stab at making a Example 1: SV = PV(0x811f470) at 0x8129cf8 We are saying that this example should probably return a utf8 string. Example 2: SV = PV(0x811f470) at 0x8129cf0 Notice that $c is a utf8 string before read() is called, so the Therefore, my suggestion would be that we only return a utf8 string if Sound good? Chris |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#31459 (status was 'resolved')
Searchable as RT31459$
The text was updated successfully, but these errors were encountered: