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) { |
245 | 245 | } |
246 | 246 | |
247 | 247 | int ASYNC_VERIFY::verify_chunk() { |
248 | | int n; |
| 248 | size_t n; |
249 | 249 | unsigned char buf[BUFSIZE]; |
250 | 250 | if (fip->download_gzipped) { |
251 | 251 | n = gzread(gzin, buf, BUFSIZE); |
… |
… |
int ASYNC_VERIFY::verify_chunk() { |
259 | 259 | finish(); |
260 | 260 | return 1; |
261 | 261 | } else { |
262 | | int m = (int)fwrite(buf, 1, n, out); |
| 262 | size_t m = fwrite(buf, 1, n, out); |
263 | 263 | if (m != n) { |
264 | 264 | // write failed |
265 | 265 | // |
266 | 266 | error(ERR_FWRITE); |
267 | 267 | return 1; |
268 | 268 | } |
269 | | md5_append(&md5_state, buf, n); |
| 269 | md5_append(&md5_state, buf, (int)n); |
270 | 270 | } |
271 | 271 | } else { |
272 | 272 | n = fread(buf, 1, BUFSIZE, in); |
273 | | if (n <= 0) { |
| 273 | if (!n) { |
274 | 274 | fclose(in); |
275 | 275 | finish(); |
276 | 276 | return 1; |
277 | 277 | } else { |
278 | | md5_append(&md5_state, buf, n); |
| 278 | md5_append(&md5_state, buf, (int)n); |
279 | 279 | } |
280 | 280 | } |
281 | 281 | return 0; |