-
Notifications
You must be signed in to change notification settings - Fork 496
Description
Problem
The functions that require a 1wire address, like bool DallasTemperature::getAddress(uint8_t*, uint8_t)
have a missleading prototype, as we expect, after reading their definition in the DallasTemperature.h to be called like uint8_t my_address; bool ok = ds.getAddress(&my_address,0)
. This is actually incorrect, because we don't expect a pointer on uint8_t, but an array of exactly 8 uint8_t.
The parameters are not named in the DallasTemperature.h file, and it's hard to guess which parameter is what by solely looking at their type. Please name them with something meaningfull that describe what they do.
Patch proposal 1 : use types
class DallasTemperature {
public:
typedef uint8_t[8] Address_t;
bool getAddress(Address_t address, uint8_t index);
...
}
Patch proposal 2 : use the correct type for address : uint8_t[8] not uint8_t*
class DallasTemperature {
public:
bool getAddress(uint8_t address[8] , uint8_t index);
...
}
Drawback : break wired code
This patch will break the code of some people that uses wired memory buffer management like
uint8_t mempool[128];
bool ok = ds.getAddress(&mempool[42] , 0);
But such code is missleading code too, and should be patched to use an explicit cast + a comment that explain what we're doing anyway, so breaking it may be anoying for a good reason.