Commit c92d7c3b authored by Sergey Lyubka's avatar Sergey Lyubka

Fix for Android: fread() might return < 0

parent ee91109d
...@@ -2581,16 +2581,19 @@ static void send_file_data(struct mg_connection *conn, FILE *fp, int64_t len) { ...@@ -2581,16 +2581,19 @@ static void send_file_data(struct mg_connection *conn, FILE *fp, int64_t len) {
while (len > 0) { while (len > 0) {
// Calculate how much to read from the file in the buffer // Calculate how much to read from the file in the buffer
to_read = sizeof(buf); to_read = sizeof(buf);
if ((int64_t) to_read > len) if ((int64_t) to_read > len) {
to_read = (int) len; to_read = (int) len;
}
// Read from file, exit the loop on error // 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; break;
}
// Send read bytes to the client, exit the loop on error // 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; break;
}
// Both read and were successful, adjust counters // Both read and were successful, adjust counters
conn->num_bytes_sent += num_written; conn->num_bytes_sent += num_written;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment