mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-17 10:49:47 +00:00
Fix for Android: fread() might return < 0
This commit is contained in:
1 parent
ee91109d9f
commit
c92d7c3bc8
1 file changed
+6
-3
+6
-3
@@ -2581,16 +2581,19 @@ static void send_file_data(struct mg_connection *conn, FILE *fp, int64_t len) {
|
||||
while (len > 0) {
|
||||
// Calculate how much to read from the file in the buffer
|
||||
to_read = sizeof(buf);
|
||||
if ((int64_t) to_read > len)
|
||||
if ((int64_t) to_read > len) {
|
||||
to_read = (int) len;
|
||||
}
|
||||
|
||||
// Read from file, exit the loop on error
|
||||
if ((num_read = fread(buf, 1, (size_t)to_read, fp)) == 0)
|
||||
if ((num_read = fread(buf, 1, (size_t)to_read, fp)) <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Send read bytes to the client, exit the loop on error
|
||||
if ((num_written = mg_write(conn, buf, (size_t)num_read)) != num_read)
|
||||
if ((num_written = mg_write(conn, buf, (size_t)num_read)) != num_read) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Both read and were successful, adjust counters
|
||||
conn->num_bytes_sent += num_written;
|
||||
|
||||
Reference in new issue
Block a user