Skip to content

Update ArduinoOTA.cpp to solve #4086 #4090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2018
Merged

Update ArduinoOTA.cpp to solve #4086 #4090

merged 2 commits into from
Jan 4, 2018

Conversation

lrmoreno007
Copy link
Contributor

Update ArduinoOTA.cpp to solve #4086

}
return 0;
}

String ArduinoOTAClass::readStringUntil(char end){
String res = "";
int value;
char value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value should be declared int, because read() returns an int that can be -1 on error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation is back to original before yoursunny PR (it was char) and homogenize data types ( '/0' and end are char)

@@ -146,26 +146,26 @@ int ArduinoOTAClass::parseInt(){
uint8_t index;
char value;
while(_udp_ota->peek() == ' ') _udp_ota->read();
for(index = 0; index < sizeof(data); ++index){
for(index = 0; index < sizeof(data); index++){
value = _udp_ota->peek();
if(value < '0' || value > '9'){
data[index++] = '\0';
Copy link
Contributor

@Juppit Juppit Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it would be even clearer to not increment the index here, something like this:
data[index+1] = '\0';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be data[index] = '\0';

@@ -146,26 +146,26 @@ int ArduinoOTAClass::parseInt(){
uint8_t index;
char value;
while(_udp_ota->peek() == ' ') _udp_ota->read();
for(index = 0; index < sizeof(data); ++index){
for(index = 0; index < sizeof(data); index++){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is undesired (++index is better style in C++ in a for loop)

@@ -146,26 +146,26 @@ int ArduinoOTAClass::parseInt(){
uint8_t index;
char value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value should be declared int, because peek() returns an int that can be -1 on error

@@ -146,26 +146,26 @@ int ArduinoOTAClass::parseInt(){
uint8_t index;
char value;
while(_udp_ota->peek() == ' ') _udp_ota->read();
for(index = 0; index < sizeof(data); ++index){
for(index = 0; index < sizeof(data); index++){
value = _udp_ota->peek();
if(value < '0' || value > '9'){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement needs a check against peek error return: if(value < 0 || everythingelse)

}
return 0;
}

String ArduinoOTAClass::readStringUntil(char end){
String res = "";
int value;
char value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value should be declared int, because read() returns an int that can be -1 on error

while(true){
value = _udp_ota->read();
if(value < 0 || value == '\0' || value == end){
if(value < '0' || value == '\0' || value == end){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs to be undon. The check value < 0 was meant to cover an error return from peek() or read(). Undo.

return res;
}
res += static_cast<char>(value);
res += value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs to be undone, given that value needs to be an int.

@@ -146,26 +146,26 @@ int ArduinoOTAClass::parseInt(){
uint8_t index;
char value;
while(_udp_ota->peek() == ' ') _udp_ota->read();
for(index = 0; index < sizeof(data); ++index){
for(index = 0; index < sizeof(data); index++){
value = _udp_ota->peek();
if(value < '0' || value > '9'){
data[index++] = '\0';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be data[index] = '\0';

@devyte devyte merged commit a19ff35 into esp8266:master Jan 4, 2018
incosystem pushed a commit to incosys/Arduino that referenced this pull request Jan 8, 2018
* Update ArduinoOTA.cpp

* Update ArduinoOTA.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants