Skip to content
Permalink
Browse files

examples/fopen: fix comparison

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 #3975
  • Loading branch information...
MarcelRaad committed May 25, 2019
1 parent e23c52b commit 992083b1abe2f19947abe1d5ba01c488458f6e66
Showing with 1 addition and 1 deletion.
  1. +1 −1 docs/examples/fopen.c
@@ -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;

0 comments on commit 992083b

Please sign in to comment.
You can’t perform that action at this time.