-
Notifications
You must be signed in to change notification settings - Fork 193
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
Check before attempting to perform a zero-length fread #72
Check before attempting to perform a zero-length fread #72
Conversation
@@ -510,8 +510,12 @@ private function getPartBodyFromFile(&$part) | |||
{ | |||
$start = $part['starting-pos-body']; | |||
$end = $part['ending-pos-body']; | |||
fseek($this->stream, $start, SEEK_SET); | |||
return fread($this->stream, $end-$start); | |||
$body = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
Thanks for your contribution to improve the quality. Do you have a test file where start > end to add it to the project ? Also I prefer to write if ($end-$start>0) return '';
fseek($this->stream, $start, SEEK_SET);
return fread($this->stream, $end-$start); What do you think ? |
@@ -510,6 +510,7 @@ private function getPartBodyFromFile(&$part) | |||
{ | |||
$start = $part['starting-pos-body']; | |||
$end = $part['ending-pos-body']; | |||
if ($end-$start <= 0) return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline control structures are not allowed
I prefer your way too, just didn't want to be shout at because of introducing multiple returns, that tend to irritate a lot of people ^^ Salut depuis Montpellier ! |
lol, the auto reviewer shouts at us now ^^ |
@@ -510,6 +510,9 @@ private function getPartBodyFromFile(&$part) | |||
{ | |||
$start = $part['starting-pos-body']; | |||
$end = $part['ending-pos-body']; | |||
if ($end-$start <= 0) { | |||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
Mhh... and now coverage decreases because of multiple returns, I guess. What do you think ? Do I revert back to the first version ? Ultimately, it seems to be the most politically correct way, regarding coverage requirements. |
No we need to add the test file to the test and check that body return '' in the case of zero-length body content |
added a test with a zero-length body example message
Mh, I don't understand why Travis CI build failed (I'm pretty new to all those tools). Anyway all the tests work on my copy, so my skills stop here, I lend this over to you. Cheers |
Thanks I will try to merge soon. |
Sorry for putting pressure to this, but I think this is a critical error which should be merged soon. |
Check before attempting to perform a zero-length fread
Thanks to pressure me, I totaly forgot it. |
Avoids a Warning thrown by fread() in case of zero-length message body