Skip to content

Commit 4aeb0f5

Browse files
authoredOct 5, 2020
Use direct member initialization instead of ctr initialisation (#7558)
* Use direct member initialization instead of ctr initialisation This removes a bit of code repetition. * Add symbolic names for member initializers
1 parent 8b8639e commit 4aeb0f5

File tree

12 files changed

+59
-132
lines changed

12 files changed

+59
-132
lines changed
 

‎cores/esp8266/Print.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@
3535

3636
class Print {
3737
private:
38-
int write_error;
38+
int write_error = 0;
3939
template<typename T> size_t printNumber(T n, uint8_t base);
4040
template<typename T, typename... P> inline size_t _println(T v, P... args);
41-
protected:
41+
protected:
4242
void setWriteError(int err = 1) {
4343
write_error = err;
4444
}
4545
public:
46-
Print() :
47-
write_error(0) {
48-
}
46+
Print() {}
4947

5048
int getWriteError() {
5149
return write_error;

‎cores/esp8266/Stream.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
class Stream: public Print {
3939
protected:
40-
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
40+
unsigned long _timeout = 1000; // number of milliseconds to wait for the next char before aborting timed read
4141
unsigned long _startMillis; // used for timeout measurement
4242
int timedRead(); // private method to read stream with timeout
4343
int timedPeek(); // private method to peek stream with timeout
@@ -48,9 +48,7 @@ class Stream: public Print {
4848
virtual int read() = 0;
4949
virtual int peek() = 0;
5050

51-
Stream() {
52-
_timeout = 1000;
53-
}
51+
Stream() {}
5452

5553
// parsing methods
5654

‎cores/esp8266/Updater.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ extern "C" uint32_t _FS_start;
2727
extern "C" uint32_t _FS_end;
2828

2929
UpdaterClass::UpdaterClass()
30-
: _async(false)
31-
, _error(0)
32-
, _buffer(0)
33-
, _bufferLen(0)
34-
, _size(0)
35-
, _startAddress(0)
36-
, _currentAddress(0)
37-
, _command(U_FLASH)
38-
, _ledPin(-1)
39-
, _hash(nullptr)
40-
, _verify(nullptr)
41-
, _progress_callback(nullptr)
4230
{
4331
#if ARDUINO_SIGNING
4432
installSignature(&esp8266::updaterSigningHash, &esp8266::updaterSigningVerifier);

‎cores/esp8266/Updater.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -182,27 +182,27 @@ class UpdaterClass {
182182

183183
void _setError(int error);
184184

185-
bool _async;
186-
uint8_t _error;
187-
uint8_t *_buffer;
188-
size_t _bufferLen; // amount of data written into _buffer
189-
size_t _bufferSize; // total size of _buffer
190-
size_t _size;
191-
uint32_t _startAddress;
192-
uint32_t _currentAddress;
193-
uint32_t _command;
185+
bool _async = false;
186+
uint8_t _error = 0;
187+
uint8_t *_buffer = nullptr;
188+
size_t _bufferLen = 0; // amount of data written into _buffer
189+
size_t _bufferSize = 0; // total size of _buffer
190+
size_t _size = 0;
191+
uint32_t _startAddress = 0;
192+
uint32_t _currentAddress = 0;
193+
uint32_t _command = U_FLASH;
194194

195195
String _target_md5;
196196
MD5Builder _md5;
197197

198-
int _ledPin;
198+
int _ledPin = -1;
199199
uint8_t _ledOn;
200200

201201
// Optional signed binary verification
202-
UpdaterHashClass *_hash;
203-
UpdaterVerifyClass *_verify;
202+
UpdaterHashClass *_hash = nullptr;
203+
UpdaterVerifyClass *_verify = nullptr;
204204
// Optional progress callback function
205-
THandlerFunction_Progress _progress_callback;
205+
THandlerFunction_Progress _progress_callback = nullptr;
206206
};
207207

208208
extern UpdaterClass Update;

‎libraries/EEPROM/EEPROM.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,11 @@ extern "C" uint32_t _EEPROM_start;
3535

3636
EEPROMClass::EEPROMClass(uint32_t sector)
3737
: _sector(sector)
38-
, _data(0)
39-
, _size(0)
40-
, _dirty(false)
4138
{
4239
}
4340

4441
EEPROMClass::EEPROMClass(void)
4542
: _sector((((uint32_t)&_EEPROM_start - 0x40200000) / SPI_FLASH_SEC_SIZE))
46-
, _data(0)
47-
, _size(0)
48-
, _dirty(false)
4943
{
5044
}
5145

‎libraries/EEPROM/EEPROM.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class EEPROMClass {
6868

6969
protected:
7070
uint32_t _sector;
71-
uint8_t* _data;
72-
size_t _size;
73-
bool _dirty;
71+
uint8_t* _data = nullptr;
72+
size_t _size = 0;
73+
bool _dirty = false;
7474
};
7575

7676
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)

‎libraries/ESP8266SSDP/ESP8266SSDP.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ extern "C" {
4747
#include "include/UdpContext.h"
4848
//#define DEBUG_SSDP Serial
4949

50-
#define SSDP_INTERVAL 1200
5150
#define SSDP_PORT 1900
5251
#define SSDP_METHOD_SIZE 10
5352
#define SSDP_URI_SIZE 2
5453
#define SSDP_BUFFER_SIZE 64
55-
#define SSDP_MULTICAST_TTL 2
5654

5755
// ssdp ipv6 is FF05::C
5856
// lwip-v2's igmp_joingroup only supports IPv4
@@ -125,19 +123,8 @@ struct SSDPTimer {
125123
ETSTimer timer;
126124
};
127125

128-
SSDPClass::SSDPClass() :
129-
_server(0),
130-
_timer(0),
131-
_port(80),
132-
_ttl(SSDP_MULTICAST_TTL),
133-
_interval(SSDP_INTERVAL),
134-
_respondToAddr(0,0,0,0),
135-
_respondToPort(0),
136-
_pending(false),
137-
_st_is_uuid(false),
138-
_delay(0),
139-
_process_time(0),
140-
_notify_time(0)
126+
SSDPClass::SSDPClass()
127+
: _respondToAddr(0,0,0,0)
141128
{
142129
_uuid[0] = '\0';
143130
_modelNumber[0] = '\0';

‎libraries/ESP8266SSDP/ESP8266SSDP.h

+14-11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class UdpContext;
4646
#define SSDP_MODEL_VERSION_SIZE 32
4747
#define SSDP_MANUFACTURER_SIZE 64
4848
#define SSDP_MANUFACTURER_URL_SIZE 128
49+
#define SSDP_INTERVAL_SECONDS 1200
50+
#define SSDP_MULTICAST_TTL 2
51+
#define SSDP_HTTP_PORT 80
4952

5053
typedef enum {
5154
NONE,
@@ -101,20 +104,20 @@ class SSDPClass{
101104
void _stopTimer();
102105
static void _onTimerStatic(SSDPClass* self);
103106

104-
UdpContext* _server;
105-
SSDPTimer* _timer;
106-
uint16_t _port;
107-
uint8_t _ttl;
108-
uint32_t _interval;
107+
UdpContext* _server = nullptr;
108+
SSDPTimer* _timer = nullptr;
109+
uint16_t _port = SSDP_HTTP_PORT;
110+
uint8_t _ttl = SSDP_MULTICAST_TTL;
111+
uint32_t _interval = SSDP_INTERVAL_SECONDS;
109112

110113
IPAddress _respondToAddr;
111-
uint16_t _respondToPort;
114+
uint16_t _respondToPort = 0;
112115

113-
bool _pending;
114-
bool _st_is_uuid;
115-
unsigned short _delay;
116-
unsigned long _process_time;
117-
unsigned long _notify_time;
116+
bool _pending = false;
117+
bool _st_is_uuid = false;
118+
unsigned short _delay = 0;
119+
unsigned long _process_time = 0;
120+
unsigned long _notify_time = 0;
118121

119122
char _schemaURL[SSDP_SCHEMA_URL_SIZE];
120123
char _uuid[SSDP_UUID_SIZE];

‎libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

-35
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,12 @@ namespace esp8266webserver {
3939
template <typename ServerType>
4040
ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(IPAddress addr, int port)
4141
: _server(addr, port)
42-
, _currentMethod(HTTP_ANY)
43-
, _currentVersion(0)
44-
, _currentStatus(HC_NONE)
45-
, _statusChange(0)
46-
, _keepAlive(false)
47-
, _currentHandler(nullptr)
48-
, _firstHandler(nullptr)
49-
, _lastHandler(nullptr)
50-
, _currentArgCount(0)
51-
, _currentArgs(nullptr)
52-
, _currentArgsHavePlain(0)
53-
, _postArgsLen(0)
54-
, _postArgs(nullptr)
55-
, _headerKeysCount(0)
56-
, _currentHeaders(nullptr)
57-
, _contentLength(0)
58-
, _chunked(false)
59-
, _corsEnabled(false)
6042
{
6143
}
6244

6345
template <typename ServerType>
6446
ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(int port)
6547
: _server(port)
66-
, _currentMethod(HTTP_ANY)
67-
, _currentVersion(0)
68-
, _currentStatus(HC_NONE)
69-
, _statusChange(0)
70-
, _currentHandler(nullptr)
71-
, _firstHandler(nullptr)
72-
, _lastHandler(nullptr)
73-
, _currentArgCount(0)
74-
, _currentArgs(nullptr)
75-
, _currentArgsHavePlain(0)
76-
, _postArgsLen(0)
77-
, _postArgs(nullptr)
78-
, _headerKeysCount(0)
79-
, _currentHeaders(nullptr)
80-
, _contentLength(0)
81-
, _chunked(false)
82-
, _corsEnabled(false)
8348
{
8449
}
8550

‎libraries/ESP8266WebServer/src/ESP8266WebServer.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -263,35 +263,35 @@ class ESP8266WebServerTemplate
263263

264264
ServerType _server;
265265
ClientType _currentClient;
266-
HTTPMethod _currentMethod;
266+
HTTPMethod _currentMethod = HTTP_ANY;
267267
String _currentUri;
268-
uint8_t _currentVersion;
269-
HTTPClientStatus _currentStatus;
270-
unsigned long _statusChange;
271-
bool _keepAlive;
272-
273-
RequestHandlerType* _currentHandler;
274-
RequestHandlerType* _firstHandler;
275-
RequestHandlerType* _lastHandler;
268+
uint8_t _currentVersion = 0;
269+
HTTPClientStatus _currentStatus = HC_NONE;
270+
unsigned long _statusChange = 0;
271+
272+
RequestHandlerType* _currentHandler = nullptr;
273+
RequestHandlerType* _firstHandler = nullptr;
274+
RequestHandlerType* _lastHandler = nullptr;
276275
THandlerFunction _notFoundHandler;
277276
THandlerFunction _fileUploadHandler;
278277

279-
int _currentArgCount;
280-
RequestArgument* _currentArgs;
281-
int _currentArgsHavePlain;
278+
int _currentArgCount = 0;
279+
RequestArgument* _currentArgs = nullptr;
280+
int _currentArgsHavePlain = 0;
282281
std::unique_ptr<HTTPUpload> _currentUpload;
283-
int _postArgsLen;
284-
RequestArgument* _postArgs;
282+
int _postArgsLen = 0;
283+
RequestArgument* _postArgs = nullptr;
285284

286-
int _headerKeysCount;
287-
RequestArgument* _currentHeaders;
285+
int _headerKeysCount = 0;
286+
RequestArgument* _currentHeaders = nullptr;
288287

289-
size_t _contentLength;
288+
size_t _contentLength = 0;
290289
String _responseHeaders;
291290

292291
String _hostHeader;
293-
bool _chunked;
294-
bool _corsEnabled;
292+
bool _chunked = false;
293+
bool _corsEnabled = false;
294+
bool _keepAlive = false;
295295

296296
String _snonce; // Store noance and opaque for future comparison
297297
String _sopaque;

‎libraries/ESP8266WiFi/src/WiFiServer.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,12 @@ extern "C" {
4444
WiFiServer::WiFiServer(const IPAddress& addr, uint16_t port)
4545
: _port(port)
4646
, _addr(addr)
47-
, _listen_pcb(nullptr)
48-
, _unclaimed(nullptr)
49-
, _discarded(nullptr)
5047
{
5148
}
5249

5350
WiFiServer::WiFiServer(uint16_t port)
5451
: _port(port)
5552
, _addr(IP_ANY_TYPE)
56-
, _listen_pcb(nullptr)
57-
, _unclaimed(nullptr)
58-
, _discarded(nullptr)
5953
{
6054
}
6155

‎libraries/ESP8266WiFi/src/WiFiServer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ class WiFiServer : public Server {
7070
protected:
7171
uint16_t _port;
7272
IPAddress _addr;
73-
tcp_pcb* _listen_pcb;
73+
tcp_pcb* _listen_pcb = nullptr;
7474

75-
ClientContext* _unclaimed;
76-
ClientContext* _discarded;
75+
ClientContext* _unclaimed = nullptr;
76+
ClientContext* _discarded = nullptr;
7777
enum { _ndDefault, _ndFalse, _ndTrue } _noDelay = _ndDefault;
7878

7979
public:

0 commit comments

Comments
 (0)
Please sign in to comment.