From d41b335aeef825a52474a8fd1fadcd2f87bfe639 Mon Sep 17 00:00:00 2001 From: Gregg Date: Fri, 22 Jan 2021 21:37:29 -0600 Subject: [PATCH] Cleaned up various compiler warnings when compiled with max warning level Also added a missing check on hapServer existing before it is used (bug introduced in last update where hapServer became dynamically initialized). --- src/HAP.cpp | 25 ++++++++++++++----------- src/HomeSpan.cpp | 28 +++++++++++++++++----------- src/Network.cpp | 6 +++--- src/TLV.h | 4 +++- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/HAP.cpp b/src/HAP.cpp index 150a8df..0ccd436 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -647,6 +647,8 @@ int HAPClient::postPairSetupURL(){ } // switch + return(1); + } // postPairSetup ////////////////////////////////////// @@ -701,7 +703,7 @@ int HAPClient::postPairVerifyURL(){ memcpy(iosCurveKey,tlv8.buf(kTLVType_PublicKey),32); // save iosCurveKey (will persist until end of verification process) - int rVal=crypto_scalarmult_curve25519(sharedCurveKey,secretCurveKey,iosCurveKey); // generate (and persist) Pair Verify SharedSecret CurveKey from Accessory's Curve25519 secret key and Controller's Curve25519 public key (32 bytes) + crypto_scalarmult_curve25519(sharedCurveKey,secretCurveKey,iosCurveKey); // generate (and persist) Pair Verify SharedSecret CurveKey from Accessory's Curve25519 secret key and Controller's Curve25519 public key (32 bytes) uint8_t *accessoryPairingID = accessory.ID; // set accessoryPairingID size_t accessoryPairingIDLen = 17; @@ -842,6 +844,8 @@ int HAPClient::postPairVerifyURL(){ break; } // switch + + return(1); } // postPairVerify @@ -925,7 +929,7 @@ int HAPClient::postPairingsURL(){ break; } - if(newCont=findController(tlv8.buf(kTLVType_Identifier))){ + if((newCont=findController(tlv8.buf(kTLVType_Identifier)))){ tlv8.clear(); // clear TLV records tlv8.val(kTLVType_State,pairState_M2); // set State= if(!memcmp(cPair->LTPK,newCont->LTPK,32)){ // requested Controller already exists and LTPK matches @@ -1187,10 +1191,10 @@ int HAPClient::putPrepareURL(char *json){ uint32_t ttl; uint64_t pid; - if(cBuf=strstr(json,ttlToken)) - sscanf(cBuf+strlen(ttlToken),"%lu",&ttl); + if((cBuf=strstr(json,ttlToken))) + sscanf(cBuf+strlen(ttlToken),"%u",&ttl); - if(cBuf=strstr(json,pidToken)) + if((cBuf=strstr(json,pidToken))) sscanf(cBuf+strlen(ttlToken),"%llu",&pid); char jsonBuf[32]; @@ -1202,7 +1206,7 @@ int HAPClient::putPrepareURL(char *json){ status=StatusCode::InvalidValue; } - sprintf(jsonBuf,"{\"status\":%d}",status); + sprintf(jsonBuf,"{\"status\":%d}",(int)status); int nBytes=strlen(jsonBuf); int nChars=snprintf(NULL,0,"HTTP/1.1 200 OK\r\nContent-Type: application/hap+json\r\nContent-Length: %d\r\n\r\n",nBytes); // create Body with Content Length = size of JSON Buf char body[nChars+1]; @@ -1264,7 +1268,7 @@ void HAPClient::checkTimedWrites(){ for(auto tw=homeSpan.TimedWrites.begin(); tw!=homeSpan.TimedWrites.end(); tw++){ // loop over all Timed Writes using an iterator if(cTime>tw->second){ // timer has expired - sprintf(c,"Removing PID=%llu ALARM=%lu\n",tw->first,tw->second); + sprintf(c,"Removing PID=%llu ALARM=%u\n",tw->first,tw->second); LOG2(c); homeSpan.TimedWrites.erase(tw); } @@ -1338,7 +1342,6 @@ void HAPClient::tlvRespond(){ int HAPClient::receiveEncrypted(){ uint8_t buf[1042]; // maximum size of encoded message = 2+1024+16 bytes (HAP Section 6.5.2) - int nFrames=0; int nBytes=0; while(client.read(buf,2)==2){ // read initial 2-byte AAD record @@ -1498,7 +1501,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){ Controller *slot; - if(slot=findController(id)){ + if((slot=findController(id))){ memcpy(slot->LTPK,ltpk,32); slot->admin=admin; LOG2("\n*** Updated Controller: "); @@ -1508,7 +1511,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){ return(slot); } - if(slot=getFreeController()){ + if((slot=getFreeController())){ slot->allocated=true; memcpy(slot->ID,id,36); memcpy(slot->LTPK,ltpk,32); @@ -1553,7 +1556,7 @@ void HAPClient::removeController(uint8_t *id){ Controller *slot; - if(slot=findController(id)){ // remove controller if found + if((slot=findController(id))){ // remove controller if found LOG2("\n***Removed Controller: "); if(homeSpan.logLevel>1) charPrintRow(id,36); diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 3ce1a08..6747fba 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -47,7 +47,7 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa this->displayName=displayName; this->hostNameBase=hostNameBase; this->modelName=modelName; - sprintf(this->category,"%d",catID); + sprintf(this->category,"%d",(int)catID); controlButton.init(controlPin); statusLED.init(statusPin); @@ -149,10 +149,10 @@ void Span::poll() { WiFiClient newClient; - if(newClient=hapServer->available()){ // found a new HTTP client - int freeSlot=getFreeSlot(); // get next free slot + if(hapServer && (newClient=hapServer->available())){ // found a new HTTP client + int freeSlot=getFreeSlot(); // get next free slot - if(freeSlot==-1){ // no available free slots + if(freeSlot==-1){ // no available free slots freeSlot=randombytes_uniform(maxConnections); LOG2("=======================================\n"); LOG1("** Freeing Client #"); @@ -817,7 +817,7 @@ int Span::countCharacteristics(char *buf){ int nObj=0; const char tag[]="\"aid\""; - while(buf=strstr(buf,tag)){ // count number of characteristic objects in PUT JSON request + while((buf=strstr(buf,tag))){ // count number of characteristic objects in PUT JSON request nObj++; buf+=strlen(tag); } @@ -999,7 +999,7 @@ int Span::sprintfAttributes(SpanBuf *pObj, int nObj, char *cBuf){ nChars+=snprintf(cBuf,cBuf?64:0,"{\"characteristics\":["); for(int i=0;i::create(tagType tag, int maxLen, const char *name){ tlv[numTags].name=name; tlv[numTags].len=-1; tlv[numTags].val=(uint8_t *)malloc(maxLen); - numTags++; + numTags++; + + return(1); } //////////////////////////////////////