Code

http-backend: Fix bad treatment of uintmax_t in Content-Length
[git.git] / http-backend.c
index f8ea9d7faa0494375d3d5413e91869d74252d649..7f48406d6dd8a3b67ade9a6b532a8c5764d61504 100644 (file)
@@ -134,7 +134,7 @@ static void hdr_str(const char *name, const char *value)
        format_write(1, "%s: %s\r\n", name, value);
 }
 
-static void hdr_int(const char *name, size_t value)
+static void hdr_int(const char *name, uintmax_t value)
 {
        format_write(1, "%s: %" PRIuMAX "\r\n", name, value);
 }
@@ -216,7 +216,6 @@ static void send_local_file(const char *the_type, const char *name)
        char *buf = xmalloc(buf_alloc);
        int fd;
        struct stat sb;
-       size_t size;
 
        fd = open(p, O_RDONLY);
        if (fd < 0)
@@ -224,14 +223,12 @@ static void send_local_file(const char *the_type, const char *name)
        if (fstat(fd, &sb) < 0)
                die_errno("Cannot stat '%s'", p);
 
-       size = xsize_t(sb.st_size);
-
-       hdr_int(content_length, size);
+       hdr_int(content_length, sb.st_size);
        hdr_str(content_type, the_type);
        hdr_date(last_modified, sb.st_mtime);
        end_headers();
 
-       while (size) {
+       for (;;) {
                ssize_t n = xread(fd, buf, buf_alloc);
                if (n < 0)
                        die_errno("Cannot read '%s'", p);