diff options
author | Brandon Casey <drafnel@gmail.com> | 2014-08-29 23:48:03 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2014-09-07 23:23:12 +0200 |
commit | 6beb0eeea17cd6cc71cb69737ac63861a8f18d4e (patch) | |
tree | a3845f28b7cbf165d5340c045ec71bf0763b0bef /lib/progress.c | |
parent | 8acbb074f8816156c250cd39c9ea53cbba670302 (diff) | |
download | curl-6beb0eeea17cd6cc71cb69737ac63861a8f18d4e.tar.gz |
Ensure progress.size_dl/progress.size_ul are always >= 0
Historically the default "unknown" value for progress.size_dl and
progress.size_ul has been zero, since these values are initialized
implicitly by the calloc that allocates the curl handle that these
variables are a part of. Users of curl that install progress
callbacks may expect these values to always be >= 0.
Currently it is possible for progress.size_dl and progress.size_ul
to by set to a value of -1, if Curl_pgrsSetDownloadSize() or
Curl_pgrsSetUploadSize() are passed a "size" of -1 (which a few
places currently do, and a following patch will add more). So
lets update Curl_pgrsSetDownloadSize() and Curl_pgrsSetUploadSize()
so they make sure that these variables always contain a value that
is >= 0.
Updates test579 and test599.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Diffstat (limited to 'lib/progress.c')
-rw-r--r-- | lib/progress.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/progress.c b/lib/progress.c index e6a8d825a..f147ce71e 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -159,8 +159,8 @@ void Curl_pgrsResetTimesSizes(struct SessionHandle *data) data->progress.t_pretransfer = 0.0; data->progress.t_starttransfer = 0.0; - Curl_pgrsSetDownloadSize(data, 0); - Curl_pgrsSetUploadSize(data, 0); + Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsSetUploadSize(data, -1); } void Curl_pgrsTime(struct SessionHandle *data, timerid timer) @@ -234,20 +234,26 @@ void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size) void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size) { - data->progress.size_dl = size; - if(size >= 0) + if(size >= 0) { + data->progress.size_dl = size; data->progress.flags |= PGRS_DL_SIZE_KNOWN; - else + } + else { + data->progress.size_dl = 0; data->progress.flags &= ~PGRS_DL_SIZE_KNOWN; + } } void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size) { - data->progress.size_ul = size; - if(size >= 0) + if(size >= 0) { + data->progress.size_ul = size; data->progress.flags |= PGRS_UL_SIZE_KNOWN; - else + } + else { + data->progress.size_ul = 0; data->progress.flags &= ~PGRS_UL_SIZE_KNOWN; + } } /* |