Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By martinayotte
#26761 After posting this viewtopic.php?f=8&p=26737#p26737, I've decided to start the work of adding a new WiFiClient::write_P function.
I've face a small bug which I fixed right away, but it lead be questioning myself about if the bug exists in ESP8266WebServer::sendContent_P(), it is probably there too.

The issue is that is PGM_P buffer is smaller then packet size, the first packet should not be sized to HTTP_DOWNLOAD_UNIT_SIZE ! :o

In my new WiFiClient::write_P function, it is not an issue since it received a size_t argument, I've added a if < statement...
But in ESP8266WebServer::sendContent_P(), it's rely on NULL terminated string, but doing an strlen() on PROGMEM in this case can me costly in this case ... :o
Any thought on this ? should we add a size_t to ESP8266WebServer::sendContent_P() ?
User avatar
By Makuna
#26960
martinayotte wrote:After posting this viewtopic.php?f=8&p=26737#p26737, I've decided to start the work of adding a new WiFiClient::write_P function.
I've face a small bug which I fixed right away, but it lead be questioning myself about if the bug exists in ESP8266WebServer::sendContent_P(), it is probably there too.

The issue is that is PGM_P buffer is smaller then packet size, the first packet should not be sized to HTTP_DOWNLOAD_UNIT_SIZE ! :o

In my new WiFiClient::write_P function, it is not an issue since it received a size_t argument, I've added a if < statement...
But in ESP8266WebServer::sendContent_P(), it's rely on NULL terminated string, but doing an strlen() on PROGMEM in this case can me costly in this case ... :o
Any thought on this ? should we add a size_t to ESP8266WebServer::sendContent_P() ?


What issue are you running into specifically? The buffer is used to contain a running in memory chunk of data that is sent.

Having the sendContent_P() with an optional size is a good suggestion, please add an issue to the GitHub for this.
User avatar
By martinayotte
#26962
Makuna wrote:What issue are you running into specifically? The buffer is used to contain a running in memory chunk of data that is sent.

Having the sendContent_P() with an optional size is a good suggestion, please add an issue to the GitHub for this.


Hi Makuna,

the issue I've seen is when the PROGMEM is smaller than HTTP_DOWNLOAD_UNIT_SIZE, but contentUnitLen is initialized to HTTP_DOWNLOAD_UNIT_SIZE, so the first call to _currentClient.write() will be the wrong length.

To fix that, on my side, in WiFiClient::write_P, I've added the following code before the _currentClient.write(), (it also working with binary content in buffer) :
Code: Select allif (size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = size;

In the case of ESP8266WebServer::sendContent_P(), since there is no "size" argument, we need to assume that content is always string terminated, and then maybe we can simply add the almost equivalent code :
Code: Select allsize_t actual_length = strlen(contentUnit);
if (actual_length < HTTP_DOWNLOAD_UNIT_SIZE) contentUnitLen = actual_length;

Actually, I didn't try it out for this case, but if you wish, I can do that, and submit this code to my current pending PR ...