]> granicus.if.org Git - curl/commitdiff
examples/fopen: fix comparison
authorMarcel Raad <Marcel.Raad@teamviewer.com>
Sat, 25 May 2019 17:24:13 +0000 (19:24 +0200)
committerMarcel Raad <Marcel.Raad@teamviewer.com>
Wed, 5 Jun 2019 18:38:08 +0000 (20:38 +0200)
As want is size_t, (file->buffer_pos - want) is unsigned, so checking
if it's less than zero makes no sense.
Check if file->buffer_pos is less than want instead to avoid the
unsigned integer wraparound.

Closes https://github.com/curl/curl/pull/3975

docs/examples/fopen.c

index f1706fbe634bbe5f50b73b817a0a57de488054b5..7151adddec2098854067063897dda1d554927803 100644 (file)
@@ -211,7 +211,7 @@ static int fill_buffer(URL_FILE *file, size_t want)
 static int use_buffer(URL_FILE *file, size_t want)
 {
   /* sort out buffer */
-  if((file->buffer_pos - want) <= 0) {
+  if(file->buffer_pos <= want) {
     /* ditch buffer - write will recreate */
     free(file->buffer);
     file->buffer = NULL;