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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

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)

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)

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';

return atoi(data);
}
data[index++] = _udp_ota->read();
data[index] = _udp_ota->read();
}
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)

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.

}
return res;
}
Expand Down