-
Notifications
You must be signed in to change notification settings - Fork 560
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
Odd behavior when string filehandles and scalar assignment collide #10812
Comments
From @briandfoyCreated by @briandfoyI don't know if this is a bug, but it is certainly an odd situation In a test file, I had opened a filehandle to a string and written some Here's a short example script. Although I've written this for 5.010 #!perl open my $string_fh, '>', \my $string; $string = ''; print $string_fh "Mimi"; sub show_string { printf "%d: string is [%s] length [%d]\n\thex [%s]\n", Here's the output. (0) and (1) look fine, but it looks like perl is 0: string is [Buster likes liver treats] length [25] Turning off buffering did not change anything. Curiously, truncate(), seek()ing in the string works to overwrite some of the #!perl use Fcntl qw(:seek); open my $string_fh, '>', \my $string; seek $string_fh, 5, SEEK_SET; print $string_fh "Mimi"; sub show_string { printf "%d: string is [%s] length [%d]\n\thex [%s]\n", This gives similar output. There's a null byte before the 'uster' in (2): 0: string is [Buster likes liver treats] length [25] In this case, I expected five null bytes then 'Mimi', like I would get #!perl use Fcntl qw(:seek); open my $string_fh, '>', \my $string; seek $string_fh, 5, SEEK_SET; print $string_fh "Mimi"; sub show_string { printf "%d: string is [%s] length [%d]\n\thex [%s]\n", This gives reasonable output in (1), once I realize what is happening: 0: string is [] length [0] The fix, of course, is to not do affect the string through filehandle Perl Info
|
From @jkeenanOn Tue Nov 09 15:14:01 2010, comdog wrote:
[42:75:73:74:65:72:20:6C:69:6B:65:73:20:6C:69:76:65:72:20:74:72:65:61:74:73]
[00:75:73:74:65:72:20:6C:69:6B:65:73:20:6C:69:76:65:72:20:74:72:65:61:74:73:4D:69:6D:69]
Confirmed. Do you know why that null byte is overwriting the 'B'? |
The RT System itself - Status changed from 'new' to 'open' |
From @LeontOn Sat, Jan 7, 2012 at 3:57 AM, James E Keenan via RT
When $string is overwritten, the nullbyte is written but the buffer is Try undefining $scalar or make it an array if you want some really Leon |
From @cpansproutOn Sat Jan 07 05:30:12 2012, LeonT wrote:
Setting the scalar to a number caused a segfault before I fixed it in The bug in this ticket was fixed as a side-effect of fixing #92706 in The funny thing is that your comment came along just two days after -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#78980 (status was 'resolved')
Searchable as RT78980$
The text was updated successfully, but these errors were encountered: