Closed bizprof closed 3 years ago
There weren't many more uninitialised pointers, thankfully! Hope it makes the code more robust. Saw in the code that maximum number of parameters is set to 32 in Parsing-impl.h, might want to mention that in the documentation somewhere, too. If I recall correctly, it is once hardcoded to 32, and once to WEBSERVER_MAX_POST_ARGS, which might create issues in the future if somebody tries to increase this parameter.
The pointers actually are initialized in constructor as
WiFiWebServer::WiFiWebServer(int port)
: _server(port)
, _currentMethod(HTTP_ANY)
, _currentVersion(0)
, _currentHandler(0)
, _firstHandler(0)
, _lastHandler(0)
, _currentArgCount(0)
, _currentArgs(0)
, _headerKeysCount(0)
, _currentHeaders(0)
, _contentLength(0)
, _chunked(false)
{
}
So it's better to modify the constructor as follows
WiFiWebServer::WiFiWebServer(int port)
: _server(port)
, _currentMethod(HTTP_ANY)
, _currentVersion(0)
, _currentHandler(nullptr)
, _firstHandler(nullptr)
, _lastHandler(nullptr)
, _currentArgCount(0)
, _currentArgs(nullptr)
, _headerKeysCount(0)
#if USE_NEW_WEBSERVER_VERSION
,_currentUpload(nullptr)
,_postArgs(nullptr)
#endif
, _currentHeaders(nullptr)
, _contentLength(0)
, _chunked(false)
{
}
I'll fix it
That's great, didn't think of checking the constructor at all. In https://github.com/khoih-prog/WiFiWebServer/blob/master/src/WiFiWebServer.h, sorry about the typo with the (extra) line 350, must have been hitting ^V twice... Looks like you commented it out, but it still shows in the code somehow?
Will fix later. I'm currently checking to see what else. There are errors in 2nd PR.
No, we don't need in WiFi_HttpClient.h
static const char* kUserAgent = nullptr;
static const char* kContentLengthPrefix = nullptr;
static const char* kTransferEncodingChunked = nullptr;
because we already have in WiFi_HttpClient.cpp
const char* WiFiHttpClient::kUserAgent = "Arduino/2.2.0";
const char* WiFiHttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": ";
const char* WiFiHttpClient::kTransferEncodingChunked = HTTP_HEADER_TRANSFER_ENCODING ": " HTTP_HEADER_VALUE_CHUNKED;
Sorry about that. The "const" should have made it clear to me that a value gets assigned only once... No use creating PRs when one is tired :-) I have deleted my fork already, will just clone again when needed.
No use creating PRs when one is tired :-)
Happens to me too. No use merging PRs when one is tired :-) We definitely need some fresh air and a sip of fresh coffee. ;={
Yes, absolutely, and it's time to call it a day for me. Only 6:30pm over here, but can't think straight anymore :-) Off to brew a strong cup of coffee!
So glad we got that issue out of the way. Something I will from now on also check as I look at other code. Tomorrow I'll spend some more time on the WiFiManager again.
By the way, thanks for all your help and support, Khoi! I'm still learning C++, and it's not the easiest of languages for noobs like me...
it's not the easiest of languages for noobs like me...
No, you're not anymore. But learning something new everyday is good, even for me, and other experienced people.
I love the old and wise
ways which keeps me learning everyday
You know nothing, if you're thinking and saying you know everything.
Your knowledge is just a small grain of sand on the beach
That should be it for WiFiWebServer.