ObjFW  Check-in [9ad332a3ea]

Overview
Comment:OFStdIOStream_Win32Console: Add explicit casts
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9ad332a3eaa5a2e460b82922de5daf42eb60048cad3d0a1e1f031f65e506fdd1
User & Date: js on 2016-05-28 14:22:12
Other Links: manifest | tags
Context
2016-05-28
14:56
OFKernelEventObserver_select: Cast to of_socket_t check-in: e74fc30f5b user: js tags: trunk
14:22
OFStdIOStream_Win32Console: Add explicit casts check-in: 9ad332a3ea user: js tags: trunk
13:18
OFProcess: Improve environment handling on Win32 check-in: 0c7c53dd58 user: js tags: trunk
Changes

Modified src/OFStdIOStream_Win32Console.m from [856da3e285] to [64a809a602].

104
105
106
107
108
109
110



111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
			  length: (size_t)length
{
	void *pool = objc_autoreleasePoolPush();
	char *buffer = buffer_;
	of_char16_t *UTF16;
	size_t j = 0;




	UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t)
				    count: length];
	@try {
		DWORD UTF16Len;
		OFDataArray *rest = nil;
		size_t i = 0;

		if (!ReadConsoleW(_handle, UTF16, length, &UTF16Len, NULL))

			@throw [OFReadFailedException
			    exceptionWithObject: self
				requestedLength: length * 2];

		if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) {
			of_unichar_t c =
			    (((_incompleteUTF16Surrogate & 0x3FF) << 10) |







>
>
>







|
>







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
			  length: (size_t)length
{
	void *pool = objc_autoreleasePoolPush();
	char *buffer = buffer_;
	of_char16_t *UTF16;
	size_t j = 0;

	if (length > sizeof(UINT32_MAX))
		@throw [OFOutOfRangeException exception];

	UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t)
				    count: length];
	@try {
		DWORD UTF16Len;
		OFDataArray *rest = nil;
		size_t i = 0;

		if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len,
		    NULL))
			@throw [OFReadFailedException
			    exceptionWithObject: self
				requestedLength: length * 2];

		if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) {
			of_unichar_t c =
			    (((_incompleteUTF16Surrogate & 0x3FF) << 10) |
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
	if (length > SIZE_MAX / 2)
		@throw [OFOutOfRangeException exception];

	if (_incompleteUTF8SurrogateLen > 0) {
		of_unichar_t c;
		of_char16_t UTF16[2];
		ssize_t UTF8Len;
		size_t toCopy, UTF16Len;
		DWORD written;

		UTF8Len = -of_string_utf8_decode(
		    _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);

		OF_ENSURE(UTF8Len > 0);

		toCopy = UTF8Len - _incompleteUTF8SurrogateLen;







|
|







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
	if (length > SIZE_MAX / 2)
		@throw [OFOutOfRangeException exception];

	if (_incompleteUTF8SurrogateLen > 0) {
		of_unichar_t c;
		of_char16_t UTF16[2];
		ssize_t UTF8Len;
		size_t toCopy;
		DWORD UTF16Len, written;

		UTF8Len = -of_string_utf8_decode(
		    _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);

		OF_ENSURE(UTF8Len > 0);

		toCopy = UTF8Len - _incompleteUTF8SurrogateLen;
309
310
311
312
313
314
315



316
317
318
319
320
321
322
323
324
325
				tmp[j++] = 0xDC00 | (c & 0x3FF);
			} else
				tmp[j++] = c;

			i += UTF8Len;
		}




		if (!WriteConsoleW(_handle, tmp, j, &written, NULL) ||
		    written != j)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2];
	} @finally {
		[self freeMemory: tmp];
	}
}
@end







>
>
>
|









313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
				tmp[j++] = 0xDC00 | (c & 0x3FF);
			} else
				tmp[j++] = c;

			i += UTF8Len;
		}

		if (j > UINT32_MAX)
			@throw [OFOutOfRangeException exception];

		if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) ||
		    written != j)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2];
	} @finally {
		[self freeMemory: tmp];
	}
}
@end