Skip to content

Commit

Permalink
FIX: for callback function read_data_handler (#453)
Browse files Browse the repository at this point in the history
unify condition check for remaining vs read_bytes and remove
unneeded branch, and fix return value as the result.

Fixes #451 .
  • Loading branch information
mtasaka authored Aug 23, 2024
1 parent 78e0a0e commit 30aa6a2
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ext/curb_easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,18 @@ static size_t read_data_handler(void *ptr,
remaining = len - rbcu->offset;
str_ptr = RSTRING_PTR(str);

if( remaining < read_bytes ) {
if( remaining <= read_bytes ) {
if( remaining > 0 ) {
memcpy(ptr, str_ptr+rbcu->offset, remaining);
read_bytes = remaining;
rbcu->offset += remaining;
}
return remaining;
}
else if( remaining > read_bytes ) { // read_bytes <= remaining - send what we can fit in the buffer(ptr)
else { // read_bytes < remaining - send what we can fit in the buffer(ptr)
memcpy(ptr, str_ptr+rbcu->offset, read_bytes);
rbcu->offset += read_bytes;
}
else { // they're equal
memcpy(ptr, str_ptr+rbcu->offset, --read_bytes);
rbcu->offset += read_bytes;
}
return read_bytes;
}
else {
Expand Down

0 comments on commit 30aa6a2

Please sign in to comment.