Skip to content

Commit f9ac524

Browse files
Add -Werror to acceptance builds for C and CPP (#4369)
Use platform.local.txt to add -Werror to GCC for the build of all code. Any warnings on a submitted patch will cause an error. Several examples and libraries had warnings/errors (missing returns on functions, types, etc.). Clean those up with this commit as well.
1 parent ad42ab6 commit f9ac524

File tree

22 files changed

+73
-51
lines changed

22 files changed

+73
-51
lines changed

libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void setup() {
5555
}
5656
});
5757

58-
ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); });
58+
ArduinoOTA.onError([](ota_error_t error) { (void)error; ESP.restart(); });
5959

6060
/* setup the OTA server */
6161
ArduinoOTA.begin();

libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ IPAddress netMsk(255, 255, 255, 0);
4444
boolean connect;
4545

4646
/** Last time I tried to connect to WLAN */
47-
long lastConnectTry = 0;
47+
unsigned long lastConnectTry = 0;
4848

4949
/** Current WLAN status */
50-
int status = WL_IDLE_STATUS;
50+
unsigned int status = WL_IDLE_STATUS;
5151

5252
void setup() {
5353
delay(1000);
@@ -95,7 +95,7 @@ void loop() {
9595
lastConnectTry = millis();
9696
}
9797
{
98-
int s = WiFi.status();
98+
unsigned int s = WiFi.status();
9999
if (s == 0 && millis() > (lastConnectTry + 60000) ) {
100100
/* If WLAN disconnected and idle try to connect */
101101
/* Don't set retry time too low as retry interfere the softAP operation */

libraries/DNSServer/examples/CaptivePortalAdvanced/tools.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Is this an IP? */
22
boolean isIp(String str) {
3-
for (int i = 0; i < str.length(); i++) {
3+
for (size_t i = 0; i < str.length(); i++) {
44
int c = str.charAt(i);
55
if (c != '.' && (c < '0' || c > '9')) {
66
return false;

libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ extern "C" {
3939
#define beget16(addr) (*addr * 256 + *(addr+1))
4040

4141
ESP8266AVRISP::ESP8266AVRISP(uint16_t port, uint8_t reset_pin, uint32_t spi_freq, bool reset_state, bool reset_activehigh):
42-
_reset_pin(reset_pin), _reset_state(reset_state), _spi_freq(spi_freq), _reset_activehigh(reset_activehigh),
43-
_server(WiFiServer(port)), _state(AVRISP_STATE_IDLE)
42+
_spi_freq(spi_freq), _server(WiFiServer(port)), _state(AVRISP_STATE_IDLE),
43+
_reset_pin(reset_pin), _reset_state(reset_state), _reset_activehigh(reset_activehigh)
4444
{
4545
pinMode(_reset_pin, OUTPUT);
4646
setReset(_reset_state);
@@ -71,6 +71,7 @@ AVRISPState_t ESP8266AVRISP::update() {
7171
ip_addr_t lip;
7272
lip.addr = _client.remoteIP();
7373
AVRISP_DEBUG("client connect %d.%d.%d.%d:%d", IP2STR(&lip), _client.remotePort());
74+
(void) lip; // Avoid unused warning when not in debug mode
7475
_client.setTimeout(100); // for getch()
7576
_state = AVRISP_STATE_PENDING;
7677
_reject_incoming();
@@ -136,10 +137,9 @@ void ESP8266AVRISP::fill(int n) {
136137
}
137138

138139
uint8_t ESP8266AVRISP::spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
139-
uint8_t n;
140140
SPI.transfer(a);
141-
n = SPI.transfer(b);
142-
n = SPI.transfer(c);
141+
SPI.transfer(b);
142+
SPI.transfer(c);
143143
return SPI.transfer(d);
144144
}
145145

@@ -233,7 +233,6 @@ void ESP8266AVRISP::end_pmode() {
233233
}
234234

235235
void ESP8266AVRISP::universal() {
236-
int w;
237236
uint8_t ch;
238237

239238
fill(4);
@@ -265,8 +264,6 @@ int ESP8266AVRISP::addr_page(int addr) {
265264

266265

267266
void ESP8266AVRISP::write_flash(int length) {
268-
uint32_t started = millis();
269-
270267
fill(length);
271268

272269
if (Sync_CRC_EOP == getch()) {
@@ -331,7 +328,6 @@ void ESP8266AVRISP::program_page() {
331328
int length = 256 * getch();
332329
length += getch();
333330
char memtype = getch();
334-
char buf[100];
335331
// flash memory @here, (length) bytes
336332
if (memtype == 'F') {
337333
write_flash(length);
@@ -390,7 +386,6 @@ void ESP8266AVRISP::eeprom_read_page(int length) {
390386
}
391387

392388
void ESP8266AVRISP::read_page() {
393-
char result = (char)Resp_STK_FAILED;
394389
int length = 256 * getch();
395390
length += getch();
396391
char memtype = getch();
@@ -424,9 +419,13 @@ void ESP8266AVRISP::read_signature() {
424419

425420
// It seems ArduinoISP is based on the original STK500 (not v2)
426421
// but implements only a subset of the commands.
427-
int ESP8266AVRISP::avrisp() {
422+
void ESP8266AVRISP::avrisp() {
428423
uint8_t data, low, high;
429424
uint8_t ch = getch();
425+
// Avoid set but not used warning. Leaving them in as it helps document the code
426+
(void) data;
427+
(void) low;
428+
(void) high;
430429
// AVRISP_DEBUG("CMD 0x%02x", ch);
431430
switch (ch) {
432431
case Cmnd_STK_GET_SYNC:
@@ -517,7 +516,7 @@ int ESP8266AVRISP::avrisp() {
517516

518517
// anything else we will return STK_UNKNOWN
519518
default:
520-
AVRISP_DEBUG("??!?");
519+
AVRISP_DEBUG("?!?");
521520
error++;
522521
if (Sync_CRC_EOP == getch()) {
523522
_client.print((char)Resp_STK_UNKNOWN);

libraries/ESP8266AVRISP/src/ESP8266AVRISP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ESP8266AVRISP {
7171

7272
inline void _reject_incoming(void); // reject any incoming tcp connections
7373

74-
int avrisp(void); // handle incoming STK500 commands
74+
void avrisp(void); // handle incoming STK500 commands
7575

7676
uint8_t getch(void); // retrieve a character from the remote end
7777
uint8_t spi_transaction(uint8_t, uint8_t, uint8_t, uint8_t);

libraries/ESP8266LLMNR/ESP8266LLMNR.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ bool LLMNRResponder::begin(const char* hostname) {
8787
_hostname.toLowerCase();
8888

8989
_sta_got_ip_handler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& event){
90+
(void) event;
9091
_restart();
9192
});
9293

9394
_sta_disconnected_handler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& event) {
95+
(void) event;
9496
_restart();
9597
});
9698

@@ -122,6 +124,7 @@ bool LLMNRResponder::_restart() {
122124
_conn->setMulticastTTL(LLMNR_MULTICAST_TTL);
123125
_conn->onRx(std::bind(&LLMNRResponder::_process_packet, this));
124126
_conn->connect(multicast_addr, LLMNR_PORT);
127+
return true;
125128
}
126129

127130
void LLMNRResponder::_process_packet() {
@@ -242,8 +245,8 @@ void LLMNRResponder::_process_packet() {
242245

243246
// Header
244247
uint8_t header[] = {
245-
id >> 8, id & 0xff, // ID
246-
FLAGS_QR >> 8, 0, // FLAGS
248+
(uint8_t)(id >> 8), (uint8_t)(id & 0xff), // ID
249+
(uint8_t)(FLAGS_QR >> 8), 0, // FLAGS
247250
0, 1, // QDCOUNT
248251
0, !!have_rr, // ANCOUNT
249252
0, 0, // NSCOUNT
@@ -269,7 +272,7 @@ void LLMNRResponder::_process_packet() {
269272
0, 1, // CLASS (IN)
270273
0, 0, 0, 30, // TTL (30 seconds)
271274
0, 4, // RDLENGTH
272-
ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff, // RDATA
275+
(uint8_t)(ip & 0xff), (uint8_t)((ip >> 8) & 0xff), (uint8_t)((ip >> 16) & 0xff), (uint8_t)((ip >> 24) & 0xff) // RDATA
273276
};
274277
_conn->append(reinterpret_cast<const char*>(rr), sizeof(rr));
275278
}

libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool handleFileRead(String path){
7777
if(SPIFFS.exists(pathWithGz))
7878
path += ".gz";
7979
File file = SPIFFS.open(path, "r");
80-
size_t sent = server.streamFile(file, contentType);
80+
server.streamFile(file, contentType);
8181
file.close();
8282
return true;
8383
}

libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void loop()
129129
}
130130

131131
// send an NTP request to the time server at the given address
132-
unsigned long sendNTPpacket(IPAddress& address)
132+
void sendNTPpacket(IPAddress& address)
133133
{
134134
Serial.println("sending NTP packet...");
135135
// set all bytes in the buffer to 0

libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ unsigned int readRegister(byte registerName, int numBytes) {
204204
// take the chip select low to select the device:
205205
digitalWrite(chipSelectPin, LOW);
206206
// send the device the register you want to read:
207-
int command = SPI.transfer(registerName);
207+
SPI.transfer(registerName);
208208
// send a value of 0 to read the first byte returned:
209209
inByte = SPI.transfer(0x00);
210210

libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void loop()
108108
}
109109

110110
// send an NTP request to the time server at the given address
111-
unsigned long sendNTPpacket(char* address)
111+
void sendNTPpacket(char* address)
112112
{
113113
// set all bytes in the buffer to 0
114114
memset(packetBuffer, 0, NTP_PACKET_SIZE);

libraries/Ethernet/src/Dns.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,12 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
282282
}
283283
iUdp.read(header, DNS_HEADER_SIZE);
284284

285-
uint16_t header_flags = htons(*((uint16_t*)&header[2]));
285+
uint16_t staging; // Staging used to avoid type-punning warnings
286+
memcpy(&staging, &header[2], sizeof(uint16_t));
287+
uint16_t header_flags = htons(staging);
288+
memcpy(&staging, &header[0], sizeof(uint16_t));
286289
// Check that it's a response to this request
287-
if ( ( iRequestId != (*((uint16_t*)&header[0])) ) ||
290+
if ( ( iRequestId != staging ) ||
288291
((header_flags & QUERY_RESPONSE_MASK) != (uint16_t)RESPONSE_FLAG) )
289292
{
290293
// Mark the entire packet as read
@@ -301,7 +304,8 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
301304
}
302305

303306
// And make sure we've got (at least) one answer
304-
uint16_t answerCount = htons(*((uint16_t*)&header[6]));
307+
memcpy(&staging, &header[6], sizeof(uint16_t));
308+
uint16_t answerCount = htons(staging);
305309
if (answerCount == 0 )
306310
{
307311
// Mark the entire packet as read
@@ -310,7 +314,8 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
310314
}
311315

312316
// Skip over any questions
313-
for (uint16_t i =0; i < htons(*((uint16_t*)&header[4])); i++)
317+
memcpy(&staging, &header[4], sizeof(uint16_t));
318+
for (uint16_t i =0; i < htons(staging); i++)
314319
{
315320
// Skip over the name
316321
uint8_t len;

libraries/Ethernet/src/utility/socket.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t
364364
*/
365365
void flush(SOCKET s) {
366366
// TODO
367+
(void) s;
367368
}
368369

369370
uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len)

libraries/SD/src/SD.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ boolean callback_pathExists(SdFile& parentDir, char *filePathComponent,
241241
242242
*/
243243
SdFile child;
244+
(void) isLastComponent;
245+
(void) object;
244246

245247
boolean exists = child.open(parentDir, filePathComponent, O_RDONLY);
246248

@@ -310,6 +312,8 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
310312

311313
boolean callback_remove(SdFile& parentDir, char *filePathComponent,
312314
boolean isLastComponent, void *object) {
315+
(void) object;
316+
313317
if (isLastComponent) {
314318
return SdFile::remove(parentDir, filePathComponent);
315319
}
@@ -318,6 +322,7 @@ boolean callback_remove(SdFile& parentDir, char *filePathComponent,
318322

319323
boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
320324
boolean isLastComponent, void *object) {
325+
(void) object;
321326
if (isLastComponent) {
322327
SdFile f;
323328
if (!f.open(parentDir, filePathComponent, O_READ)) return false;

libraries/SD/src/utility/Sd2Card.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ uint8_t Sd2Card::readBlock(uint32_t block, uint8_t* dst) {
393393
*/
394394
uint8_t Sd2Card::readData(uint32_t block,
395395
uint16_t offset, uint16_t count, uint8_t* dst) {
396-
uint16_t n;
397396
if (count == 0) return true;
398397
if ((count + offset) > 512) {
399398
goto fail;
@@ -414,6 +413,8 @@ uint8_t Sd2Card::readData(uint32_t block,
414413
}
415414

416415
#ifdef OPTIMIZE_HARDWARE_SPI
416+
uint16_t n;
417+
417418
// start first spi transfer
418419
SPDR = 0XFF;
419420

libraries/SD/src/utility/SdFile.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ uint8_t SdFile::make83Name(const char* str, uint8_t* name) {
259259
i = 8; // place for extension
260260
} else {
261261
// illegal FAT characters
262-
uint8_t b;
263262
#if defined(__AVR__)
263+
uint8_t b;
264264
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
265265
while ((b = pgm_read_byte(p++))) if (b == c) return false;
266266
#elif defined(__arm__)
267+
uint8_t b;
267268
const uint8_t valid[] = "|<>^+=?/[];,*\"\\";
268269
const uint8_t *p = valid;
269270
while ((b = *p++)) if (b == c) return false;
@@ -905,7 +906,7 @@ uint8_t SdFile::rmRfStar(void) {
905906
if (!f.remove()) return false;
906907
}
907908
// position to next entry if required
908-
if (curPosition_ != (32*(index + 1))) {
909+
if (curPosition_ != (32*((uint32_t)index + 1))) {
909910
if (!seekSet(32*(index + 1))) return false;
910911
}
911912
}

libraries/SPISlave/examples/SPISlave_Test/SPISlave_Test.ino

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ void setup()
2727
// It's up to the user to implement protocol for handling data length
2828
SPISlave.onData([](uint8_t * data, size_t len) {
2929
String message = String((char *)data);
30+
(void) len;
3031
if(message.equals("Hello Slave!")) {
3132
SPISlave.setData("Hello Master!");
3233
} else if(message.equals("Are you alive?")) {
3334
char answer[33];
34-
sprintf(answer,"Alive for %u seconds!", millis() / 1000);
35+
sprintf(answer,"Alive for %lu seconds!", millis() / 1000);
3536
SPISlave.setData(answer);
3637
} else {
3738
SPISlave.setData("Say what?");

libraries/SPISlave/src/hspi_slave.c

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void ICACHE_RAM_ATTR _hspi_slave_isr_handler(void *arg)
5555
if((status & SPISWBIS) != 0 && (_hspi_slave_rx_data_cb)) {
5656
uint8_t i;
5757
uint32_t data;
58-
uint8_t buffer[33];
5958
_hspi_slave_buffer[32] = 0;
6059
for(i=0; i<8; i++) {
6160
data=SPI1W(i);

libraries/Servo/src/esp8266/Servo.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
251251

252252
void Servo::detach()
253253
{
254-
ServoTimerSequence timerId;
255-
256254
if (s_servos[_servoIndex].info.isActive) {
257255
s_servos[_servoIndex].info.isDetaching = true;
258256
}

0 commit comments

Comments
 (0)