Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in CFReadStreamGetBuffer for data streams #11

Merged
merged 1 commit into from
Dec 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions CoreFoundation/Stream.subproj/CFConcreteStreams.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,21 +592,23 @@ static CFIndex dataRead(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLen

static const UInt8 *dataGetBuffer(CFReadStreamRef stream, CFIndex maxBytesToRead, CFIndex *numBytesRead, CFStreamError *error, Boolean *atEOF, void *info) {
_CFReadDataStreamContext *dataCtxt = (_CFReadDataStreamContext *)info;
const UInt8 *bytes = CFDataGetBytePtr(dataCtxt->data);
if (dataCtxt->loc - bytes > maxBytesToRead) {
const UInt8 *bytePtr = CFDataGetBytePtr(dataCtxt->data);
CFIndex length = CFDataGetLength(dataCtxt->data);
CFIndex bytesToRead = bytePtr + length - dataCtxt->loc;
if (bytesToRead > maxBytesToRead) {
*numBytesRead = maxBytesToRead;
*atEOF = FALSE;
} else {
*numBytesRead = dataCtxt->loc - bytes;
*numBytesRead = bytesToRead;
*atEOF = TRUE;
}
error->error = 0;
bytes = dataCtxt->loc;
const UInt8 *buffer = dataCtxt->loc;
dataCtxt->loc += *numBytesRead;
if (dataCtxt->scheduled && !*atEOF) {
CFReadStreamSignalEvent(stream, kCFStreamEventHasBytesAvailable, NULL);
}
return bytes;
return buffer;
}

static Boolean dataCanRead(CFReadStreamRef stream, void *info) {
Expand Down