From c4918723c476db48c53cafe0b5373223cd1cca04 Mon Sep 17 00:00:00 2001 From: Bluebie Date: Thu, 4 Oct 2012 10:43:45 +1000 Subject: Fix off by one error in ruby HexProgram ihex parser class --- ruby/micronucleus.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ruby/micronucleus.rb b/ruby/micronucleus.rb index 3211d84..7dfafbd 100644 --- a/ruby/micronucleus.rb +++ b/ruby/micronucleus.rb @@ -127,11 +127,15 @@ class HexProgram end def binary + bytes.pack('C*') + end + + def bytes highest_address = @bytes.keys.max - - bytestring = Array.new(highest_address + 1) { |index| + + bytes = Array.new(highest_address + 1) { |index| @bytes[index] - }.pack('C*') + } end protected @@ -143,7 +147,7 @@ class HexProgram length = line[1..2].to_i(16) # usually 16 or 32 address = line[3..6].to_i(16) # 16-bit start address record_type = line[7..8].to_i(16) - data = line[9.. 9 + (length * 2)] + data = line[9... 9 + (length * 2)] checksum = line[9 + (length * 2).. 10 + (length * 2)].to_i(16) checksum_section = line[1...9 + (length * 2)] -- cgit v1.2.3