#include "DSTemperature.h"

DSTemperature::DSTemperature(byte pin) {
  _wire = new OneWire(pin);
  _addresses = (DSAddress*)malloc(sizeof(DSAddress)); 
}

void DSTemperature::begin(void) {

  DSAddress addr;

  while (_wire->search(addr.value)) {
    if (OneWire::crc8(addr.value, 7) == addr.value[7]) {
      if (_nSensors != 0)
        resizeAddresses();
      _addresses[_nSensors++] = addr;
    }
  }

  _wire->reset_search();
  delay(250);
  return;

}

void DSTemperature::resizeAddresses() {

  DSAddress* new_addresses = (DSAddress*)malloc(sizeof(DSAddress) * _nSensors);
  for (byte i = 0 ; i < _nSensors ; i++)
    new_addresses[i] = _addresses[i];
  free(_addresses);
  _addresses = new_addresses;

}

float DSTemperature::getCelsius(byte ds) {
  return CELSIUS(getRawTemperature(ds));
}

float DSTemperature::getFahrenheit(byte ds) {
  return FAHRENHEIT(getRawTemperature(ds));
}

#include "DSTemperature.h"

DSTemperature::DSTemperature(byte pin) {
  _wire = new OneWire(pin);
  _addresses = (DSAddress*)malloc(sizeof(DSAddress)); 
}

void DSTemperature::begin(void) {

  DSAddress addr;

  while (_wire->search(addr.value)) {
    if (OneWire::crc8(addr.value, 7) == addr.value[7]) {
      resizeAddresses();
      _addresses[_nSensors++] = addr;
    }
  }

  _wire->reset_search();
  delay(250);
  return;

}

void DSTemperature::resizeAddresses() {

  if (_nSensors == 0)
    return;

  DSAddress* new_addresses = (DSAddress*)malloc(sizeof(DSAddress) * _nSensors);
  for (byte i = 0 ; i < _nSensors ; i++)
    new_addresses[i] = _addresses[i];
  free(_addresses);
  _addresses = new_addresses;

}

float DSTemperature::getCelsius(byte ds) {
  return CELSIUS(getRawTemperature(ds));
}

float DSTemperature::getFahrenheit(byte ds) {
  return FAHRENHEIT(getRawTemperature(ds));
}




--- 
+++ 
@@ -11,7 +11,8 @@
 
   while (_wire->search(addr.value)) {
     if (OneWire::crc8(addr.value, 7) == addr.value[7]) {
-      resizeAddresses();
+      if (_nSensors != 0)
+        resizeAddresses();
       _addresses[_nSensors++] = addr;
     }
   }
@@ -23,9 +24,6 @@
 }
 
 void DSTemperature::resizeAddresses() {
-
-  if (_nSensors == 0)
-    return;
 
   DSAddress* new_addresses = (DSAddress*)malloc(sizeof(DSAddress) * _nSensors);
   for (byte i = 0 ; i < _nSensors ; i++)
@@ -42,6 +40,3 @@
 float DSTemperature::getFahrenheit(byte ds) {
   return FAHRENHEIT(getRawTemperature(ds));
 }
-
-
-
Call resizeAddresses only if you manage more than one sensor
