Feature #5219

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

Added by drbrain (Eric Hodel) almost 9 years ago. Updated about 8 years ago.

Target version:


If garbage characters are inserted into the pack string ruby ignores them:

$ ruby19 -e 'p [1, 2, 3].pack("*N")'

$ ruby19 -e 'p [1, 2, 3].pack("yN")'

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:


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

Updated by ko1 (Koichi Sasada) over 8 years ago

  • Tracker changed from Bug to Feature

Updated by mame (Yusuke Endoh) over 8 years ago

  • Status changed from Open to Assigned
  • Assignee set to drbrain (Eric Hodel)


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

Updated by drbrain (Eric Hodel) over 8 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) about 8 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