Unverified Commit aae10ed3 authored by Thomas Van Lenten's avatar Thomas Van Lenten Committed by GitHub

Merge pull request #4370 from felixjendrusch/objc-output-stream-write-check

Objective-C: Check return value on write of raw pointer
parents 813848d1 1da9ffe3
......@@ -942,7 +942,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state,
state_.position = length;
} else {
// Write is very big. Let's do it all at once.
[state_.output write:((uint8_t *)value) + offset maxLength:length];
NSInteger written = [state_.output write:((uint8_t *)value) + offset maxLength:length];
if (written != (NSInteger)length) {
[NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""];
}
}
}
}
......
......@@ -423,4 +423,14 @@
}
}
- (void)testThatItThrowsWhenWriteRawPtrFails {
NSOutputStream *output = [NSOutputStream outputStreamToMemory];
GPBCodedOutputStream *codedOutput =
[GPBCodedOutputStream streamWithOutputStream:output bufferSize:0]; // Skip buffering.
[output close]; // Close the output stream to force failure on write.
const char *cString = "raw";
XCTAssertThrowsSpecificNamed([codedOutput writeRawPtr:cString offset:0 length:strlen(cString)],
NSException, GPBCodedOutputStreamException_WriteFailed);
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment