[#11073] segfault printing instruction sequence for iterator — <noreply@...>

Bugs item #10527, was opened at 2007-05-02 14:42

14 messages 2007/05/02
[#11142] Re: [ ruby-Bugs-10527 ] segfault printing instruction sequence for iterator — Nobuyoshi Nakada <nobu@...> 2007/05/10

Hi,

[#11188] Re: [ ruby-Bugs-10527 ] segfault printing instruction sequence for iterator — Paul Brannan <pbrannan@...> 2007/05/16

On Thu, May 10, 2007 at 04:51:18PM +0900, Nobuyoshi Nakada wrote:

[#11234] Planning to release 1.8.6 errata — Urabe Shyouhei <shyouhei@...>

Hi all.

17 messages 2007/05/25

[ ruby-Bugs-10538 ] sub! causing unexpected side effect

From: <noreply@...>
Date: 2007-05-03 02:18:01 UTC
List: ruby-core #11074
Bugs item #10538, was opened at 2007-05-03 02:17
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10538&group_id=426

Category: Core
Group: 1.8.5
Status: Open
Resolution: None
Priority: 3
Submitted By: Carl Graff (cgramona2)
Assigned to: Nobody (None)
Summary: sub! causing unexpected side effect

Initial Comment:
I have a section of code that behaves unexpectedly in my opinion.

First the section of code:
 def adjust_bol_row(bol_row, hist_bol_row, change_disp = true)
    adj_bol_row = bol_row.dup
    adj_bol_row['DISPOSITION'] = 'ADD' if change_disp
    adj_bol_row['SHIPMENT_PRI_REF'].sub!(/-..-/,hist_bol_row['SHIPMENT_PRI_REF'][/-..-/]) if hist_bol_row
    return adj_bol_row
  end

The statement:
    adj_bol_row['SHIPMENT_PRI_REF'].sub!(/-..-/,hist_bol_row['SHIPMENT_PRI_REF'][/-..-/]) if hist_bol_row

Causes adj_bol_row['SHIPMENT_PRI_REF'] to get updated as expected BUT has the side affect of updating bol_row['SHIPMENT_PRI_REF']

When I use this code
 def adjust_bol_row(bol_row, hist_bol_row, change_disp = true)
    adj_bol_row = bol_row.dup
    adj_bol_row['DISPOSITION'] = 'ADD' if change_disp
    adj_bol_row['SHIPMENT_PRI_REF'] =
      adj_bol_row['SHIPMENT_PRI_REF'].sub(/-..-/,hist_bol_row['SHIPMENT_PRI_REF'][/-..-/]) if hist_bol_row
    return adj_bol_row
  end

Only hash element adj_bol_row['SHIPMENT_PRI_REF'] gets updated as I expect.

Why would sub! in this case cause another hash to get updated?

Thanks,
 Carl







----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10538&group_id=426

In This Thread

Prev Next