First OneWire object broken on Leo, UNO & MEGA2560 - Solved (array overrun)

I'm seeing some strange OneWire behavior on all three mentioned Arduinos. At first I suspected it was some subtle hardware incompatibility with my new Leo but I confirmed that it happens on all three mentioned Arduinos. I'm hesitant to post all my code as it's a large sketch but I'm using a OneWire array to store/access 3 OneWire objects.

const byte NUM_TEMP_SENSOR_IOS = 3;
const byte SENSOR_IO[NUM_TEMP_SENSOR_IOS] = {A0,A2,A4};
OneWire sensorBus[NUM_TEMP_SENSOR_IOS] = {
  OneWire(SENSOR_IO[0]),  //OneWire.search does not detect any devices on this IO
  OneWire(SENSOR_IO[1]),  //This IO works
  OneWire(SENSOR_IO[2]),  //This IO works
};

For some reason, the Arduino cannot find any devices on the first declared OneWire object (IO A0 in the example above). If I create a throw-away OneWire object first, then those 3 IOs that I want to use work.

const byte NUM_TEMP_SENSOR_IOS = 3;
const byte SENSOR_IO[NUM_TEMP_SENSOR_IOS] = {A0,A2,A4};
OneWire defunct(17);      //OneWire.search does not detect any devices on this IO
OneWire sensorBus[NUM_TEMP_SENSOR_IOS] = {
  OneWire(SENSOR_IO[0]),  //But these 3 IOs all work now.
  OneWire(SENSOR_IO[1]),
  OneWire(SENSOR_IO[2]),
};

I've tried issuing a temp convert command to each sensor individually (slow mode) and to all sensors on each IO collectively (fast mode). The problem is that the OneWire.search command doesn't ever find any device addresses on the first OneWire object, so it never issues any temp convert commands in slow mode because it doesn't have an address to target.

Anyways, running a simple sketch with just one or two IOs without the array works on the same hardware. It also does not matter what order I search the IOs, it matters what order I declare the OneWire objects.

Before I dive into more detail, does this sound familiar to anymore or is anyone jumping up with an idea?

So :cold_sweat:,

  for (byte i=0; i<=maxNumTempSensors; i++){
    tempSensorReadings[i] = temp;
  }

should be

  for (byte i=0; i<maxNumTempSensors; i++){
    tempSensorReadings[i] = temp;
  }

Normally I’m quite alert to those mistakes as I’m writing code.