[Avrora] Array index out of bounds exception

Yang Chen chenyang at cs.utah.edu
Sun May 18 22:41:26 PDT 2008


Hi All,

I attached my patch for it.

transmission.data is doubled when ArrayIndexOutOfBoundsException is 
catched.

Thanks in advance for any suggestion.

- Yang


--- avrora/sim/radio/Medium_orig.java	2008-05-18 23:25:20.000000000 -0700
+++ avrora/sim/radio/Medium.java	2008-05-18 23:15:36.000000000 -0700
@@ -186,7 +186,15 @@ public class Medium {
                      int indx = transmission.counter++;
                      byte val = nextByte();
                      //System.out.println("Ticker: indx"+indx);
-                    transmission.data[indx] = val;
+                    try
+                    {
+                        transmission.data[indx] = val;
+                    }
+                    catch (ArrayIndexOutOfBoundsException e)
+                    {
+                        transmission.increaseData();
+                        transmission.data[indx] = val;
+                    }
                      if (probeList != null) 
probeList.fireBeforeTransmit(Transmitter.this, val);
                      clock.insertEvent(this, cyclesPerByte);
                  }
@@ -409,6 +417,13 @@ public class Medium {
              }
              return (byte)hi;
          }
+
+        public void increaseData() {
+            int newSize = data.length * 2;
+            byte[] newData = new byte[newSize];
+            System.arraycopy(data, 0, newData, 0, data.length);
+            data = newData;
+        }
      }

      public final Synchronizer synch;


Roy Shea wrote:
> 
>> > Looks like you have a transmission that is longer than the internal
>> > 128 byte limit. That's bad. The implementation of Medium should
>> > grow this array, but it doesn't.
> 
> 
> I second this analysis.  The problem looks to be due to a simple
> overflow of a static buffer.  Avrora should probably grow the array or
> at least catch the bug and drop the packet, but it doesn't.  Fixing this
> would require one of us to go in and generate the patch.  I know that I'm
> swamped with other research :-(  If you've got the Java skills, jump in
> and send the list a patch.
> 


More information about the Avrora mailing list