Project

General

Profile

Actions

Feature #5219

closed

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

Added by drbrain (Eric Hodel) over 12 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
[ruby-core:39067]

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


Files

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
Actions #1

Updated by ko1 (Koichi Sasada) about 12 years ago

  • Tracker changed from Bug to Feature

Updated by mame (Yusuke Endoh) about 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

Updated by drbrain (Eric Hodel) about 12 years ago

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

Can you check this patch?

Actions #4

Updated by drbrain (Eric Hodel) almost 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.
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0