Ticket #1225: 0001-client-ASYNC_VERIFY-verify_chunk-delay-casting-of-si.patch

File 0001-client-ASYNC_VERIFY-verify_chunk-delay-casting-of-si.patch, 1.8 KB (added by rctay, 11 years ago)
  • client/async_file.cpp

    From ae75d4cf640a4ad015765f7b30cbf0afafad9d8d Mon Sep 17 00:00:00 2001
    From: Tay Ray Chuan <rctay89@gmail.com>
    Date: Tue, 12 Feb 2013 22:28:31 +0800
    Subject: [PATCH 1/2] client/ASYNC_VERIFY::verify_chunk: delay casting of
     size_t to int
    
    We only need ints when calling md5_append(), so do the casting at
    call-time. This reduces the number of casts needed, as well as silences
    a compiler warning on VS 2005.
    
    We need not worry about integer overflows, as md5_append checks if the
    int argument is negative.
    ---
     client/async_file.cpp | 10 +++++-----
     1 file changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/client/async_file.cpp b/client/async_file.cpp
    index 8a44a86..e8f1110 100644
    a b void ASYNC_VERIFY::error(int retval) { 
    245245}
    246246
    247247int ASYNC_VERIFY::verify_chunk() {
    248     int n;
     248    size_t n;
    249249    unsigned char buf[BUFSIZE];
    250250    if (fip->download_gzipped) {
    251251        n = gzread(gzin, buf, BUFSIZE);
    int ASYNC_VERIFY::verify_chunk() { 
    259259            finish();
    260260            return 1;
    261261        } else {
    262             int m = (int)fwrite(buf, 1, n, out);
     262            size_t m = fwrite(buf, 1, n, out);
    263263            if (m != n) {
    264264                // write failed
    265265                //
    266266                error(ERR_FWRITE);
    267267                return 1;
    268268            }
    269             md5_append(&md5_state, buf, n);
     269            md5_append(&md5_state, buf, (int)n);
    270270        }
    271271    } else {
    272272        n = fread(buf, 1, BUFSIZE, in);
    273         if (n <= 0) {
     273        if (!n) {
    274274            fclose(in);
    275275            finish();
    276276            return 1;
    277277        } else {
    278             md5_append(&md5_state, buf, n);
     278            md5_append(&md5_state, buf, (int)n);
    279279        }
    280280    }
    281281    return 0;