Feature #5219
closedArray#pack should warn (or raise) if an invalid pack string is given
Description
If garbage characters are inserted into the pack string ruby ignores them:
$ ruby19 -e 'p [1, 2, 3].pack("*N")'
"\x00\x00\x00\x01"
$ ruby19 -e 'p [1, 2, 3].pack("yN")'
"\x00\x00\x00\x01"
Ruby should at least warn like printf when -w is active:
$ ruby19 -we 'printf "%d %d", 1, 2, 3'
-e:1: warning: too many arguments for format string
A future version could raise an exception.
Files
Updated by ko1 (Koichi Sasada) almost 13 years ago
- Tracker changed from Bug to Feature
Updated by mame (Yusuke Endoh) over 12 years ago
- Status changed from Open to Assigned
- Assignee set to drbrain (Eric Hodel)
drbrain,
Ruby should at least warn like printf when -w is active:
Agreed. Could you offer a patch?
I think you can commit it, unless there is objection.
--
Yusuke Endoh mame@tsg.ne.jp
Updated by drbrain (Eric Hodel) over 12 years ago
I was helping someone else write a patch, but they have gone missing.
Can you check this patch?
Updated by drbrain (Eric Hodel) over 12 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r35292.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- pack.c (pack_pack): Warn when an invalid character is found in the
format string when $VERBOSE is true. [ruby-trunk - Feature #5219] - pack.c (pack_unpack): ditto
- test/ruby/test_pack.rb (class TestPack): Test for warnings on
invalid format characters.