diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2004-07-02 12:48:53 +0000 | 
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2004-07-02 12:48:53 +0000 | 
| commit | e4caa98901cea926fb564db4ea0cf14dd6728825 (patch) | |
| tree | 8cca7c15fccbdef4190c05d5629325dbf744395b /src | |
| parent | c211a7c68554ae1aea5697cd3911e6aad56bd8c5 (diff) | |
snprintf instead of sprintf,
better support for HUGE files with the -# progress bar
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 18 | 
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c index 775909de6..a0c04dc68 100644 --- a/src/main.c +++ b/src/main.c @@ -2413,7 +2413,7 @@ static int my_fread(void *buffer, size_t sz, size_t nmemb, void *userp)  struct ProgressData {    int calls; -  double prev; +  curl_off_t prev;    int width;    FILE *out; /* where to write everything to */    curl_off_t initial_size; @@ -2438,21 +2438,23 @@ static int myprogress (void *clientp,    int i;    struct ProgressData *bar = (struct ProgressData *)clientp; -  double total = dltotal + ultotal + bar->initial_size; -  double point = dlnow + ulnow + bar->initial_size; /* we've come this far */ +  curl_off_t total = (curl_off_t)dltotal + (curl_off_t)ultotal + +    bar->initial_size; /* expected transfer size */ +  curl_off_t point = (curl_off_t)dlnow + (curl_off_t)ulnow + +    bar->initial_size; /* we've come this far */    bar->calls++; /* simply count invokes */    if(total < 1) { -    int prevblock = (int)bar->prev / 1024; -    int thisblock = (int)point / 1024; +    curl_off_t prevblock = bar->prev / 1024; +    curl_off_t thisblock = point / 1024;      while ( thisblock > prevblock ) {        fprintf( bar->out, "#" );        prevblock++;      }    }    else { -    frac = point / total; +    frac = (double)point / (double)total;      percent = frac * 100.0f;      barwidth = bar->width - 7;      num = (int) (((double)barwidth) * frac); @@ -2461,8 +2463,8 @@ static int myprogress (void *clientp,        line[i] = '#';      }      line[i] = '\0'; -    sprintf( format, "%%-%ds %%5.1f%%%%", barwidth ); -    sprintf( outline, format, line, percent ); +    snprintf( format, sizeof(format), "%%-%ds %%5.1f%%%%", barwidth ); +    snprintf( outline, sizeof(outline), format, line, percent );      fprintf( bar->out, "\r%s", outline );    }    fflush(bar->out);  | 
