Skip to content

Commit

Permalink
basic/copy: Avoid pointless zero-sized sendfile/copy
Browse files Browse the repository at this point in the history
A while ago I copied a version of this code into libglnx, and
was recently doing some work on it:
GNOME/libglnx#44

While there I noticed that if a maximum size was provided, we could
end up doing a zero-sized `sendfile()` call which is obviously pointless.
If we have nothing to do at the of the loop, just break out.
  • Loading branch information
cgwalters committed Apr 28, 2017
1 parent 232bd67 commit ce092b5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/basic/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ int copy_bytes(int fdf, int fdt, uint64_t max_bytes, CopyFlags copy_flags) {
* but don't go below our copy buffer size, unless we are
* close the limit of bytes we are allowed to copy. */
m = MAX(MIN(COPY_BUFFER_SIZE, max_bytes), m - n);
if (m == 0)
break;
}

return 0; /* return 0 if we hit EOF earlier than the size limit */
Expand Down

0 comments on commit ce092b5

Please sign in to comment.