ObjFW  Check-in [43b963aba6]

Overview
Comment:Out of memory is way more likely for vasprintf.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 43b963aba622938ee282116681b5392ac474c84f0f1499646254bcbbd010620f
User & Date: js on 2010-04-04 15:45:22
Other Links: manifest | tags
Context
2010-04-04
16:41
Add -[readDataArrayTillEndOfStream] to OFStream. check-in: 1813376c4a user: js tags: trunk
15:45
Out of memory is way more likely for vasprintf. check-in: 43b963aba6 user: js tags: trunk
15:35
Allow throwing OFOutOfMemoryExceptions without size. check-in: a44005ee85 user: js tags: trunk
Changes

Modified src/OFMutableString.m from [80c8a0ca31] to [f8d1ab3b42].

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
	char *t;

	if (fmt == NULL)
		@throw [OFInvalidFormatException newWithClass: isa];

	if ((vasprintf(&t, [fmt cString], args)) == -1)
		/*
		 * This is only the most likely error to happen.
		 * Unfortunately, as errno isn't always thread-safe, there's
		 * no good way for us to find out what really happened.
		 */
		@throw [OFOutOfMemoryException newWithClass: isa];

	@try {
		[self appendCString: t];
	} @finally {
		free(t);







|
<
|







254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
	char *t;

	if (fmt == NULL)
		@throw [OFInvalidFormatException newWithClass: isa];

	if ((vasprintf(&t, [fmt cString], args)) == -1)
		/*
		 * This is only the most likely error to happen. Unfortunately,

		 * there is no good way to check what really happened.
		 */
		@throw [OFOutOfMemoryException newWithClass: isa];

	@try {
		[self appendCString: t];
	} @finally {
		free(t);

Modified src/OFString.m from [a9d9dd698d] to [2490a2fe1b].

461
462
463
464
465
466
467





468
469
470
471
472
473
474
475
		[super dealloc];
		@throw [OFInvalidFormatException newWithClass: c];
	}

	if ((t = vasprintf(&string, [fmt cString], args)) == -1) {
		c = isa;
		[super dealloc];





		@throw [OFInitializationFailedException newWithClass: c];
	}
	length = t;

	switch (of_string_check_utf8(string, length)) {
		case 1:
			is_utf8 = YES;
			break;







>
>
>
>
>
|







461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
		[super dealloc];
		@throw [OFInvalidFormatException newWithClass: c];
	}

	if ((t = vasprintf(&string, [fmt cString], args)) == -1) {
		c = isa;
		[super dealloc];

		/*
		 * This is only the most likely error to happen. Unfortunately,
		 * there is no good way to check what really happened.
		 */
		@throw [OFOutOfMemoryException newWithClass: c];
	}
	length = t;

	switch (of_string_check_utf8(string, length)) {
		case 1:
			is_utf8 = YES;
			break;