Feature #5219

Array#pack should warn (or raise) if an invalid pack string is given

Added by Eric Hodel over 2 years ago. Updated about 2 years ago.

[ruby-core:39067]
Status:Closed
Priority:Normal
Assignee:Eric Hodel
Category:core
Target version:2.0.0

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.

See also: https://github.com/rubinius/rubinius/issues/1127

pack.c.warn_on_unknown_directive.patch Magnifier (1.51 KB) Eric Hodel, 03/27/2012 09:09 AM

Associated revisions

Revision 35292
Added by Eric Hodel about 2 years ago

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

History

#1 Updated by Koichi Sasada about 2 years ago

  • Tracker changed from Bug to Feature

#2 Updated by Yusuke Endoh about 2 years ago

  • Status changed from Open to Assigned
  • Assignee set to 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

#3 Updated by Eric Hodel about 2 years ago

I was helping someone else write a patch, but they have gone missing.

Can you check this patch?

#4 Updated by Eric Hodel about 2 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.

Also available in: Atom PDF