cast icon indicating copy to clipboard operation
cast copied to clipboard

to_s failing for unnamed struct bit-field members

Open undurgongor opened this issue 11 years ago • 0 comments

require 'cast'
s = <<-EOS
  struct foo {
       unsigned :4;
  };

EOS
ast = C.parse(s)
ast.to_s

yields

TypeError: can't dup NilClass from .../ruby/gems/2.0.0/gems/cast-0.2.1/lib/cast/to_s.rb:48:in `dup' ...

proposed patch:

--- to_s.rb.orig        2037-08-09 14:29:46.000000000 +0200
+++ to_s.rb     2014-08-07 11:49:11.705897200 +0200
@@ -45,7 +45,7 @@
   end
   class Declarator
     def to_s
-      (indirect_type ? indirect_type.to_s(name) : name.dup) <<
+      (indirect_type ? indirect_type.to_s(name) : (name || '').dup) <<
         (init ? " = #{init}" : '') <<
         (num_bits ? " : #{num_bits}" : '')
     end

And a big "Thank you!" for cast.

undurgongor avatar Aug 07 '14 09:08 undurgongor