ObjFW  Diff

Differences From Artifact [fa334deef0]:

To Artifact [5a0f1a8428]:


185
186
187
188
189
190
191
192
193


194
195
196
197
198
199
200
185
186
187
188
189
190
191


192
193
194
195
196
197
198
199
200







-
-
+
+







{
	char *buffer = NULL;
	uintmax_t size;

	@try {
		OFFile *file;

		size = [[[OFFileManager defaultManager]
		    attributesOfItemAtPath: path] fileSize];
		size = [[OFFileManager defaultManager]
		    attributesOfItemAtPath: path].fileSize;

# if UINTMAX_MAX > SIZE_MAX
		if (size > SIZE_MAX)
			@throw [OFOutOfRangeException exception];
# endif

		if ((buffer = malloc((size_t)size)) == NULL)
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263







-
+








		_itemSize = 1;
		_count = 0;

		pageSize = [OFSystemInfo pageSize];
		buffer = [self allocMemoryWithSize: pageSize];

		while (![stream isAtEndOfStream]) {
		while (!stream.atEndOfStream) {
			size_t length = [stream readIntoBuffer: buffer
							length: pageSize];

			if (SIZE_MAX - _count < length)
				@throw [OFOutOfRangeException exception];

			_items = [self resizeMemory: _items
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+







	bool mutable = [self isKindOfClass: [OFMutableData class]];

	if (!mutable) {
		[self release];
		self = [OFMutableData alloc];
	}

	self = [(OFMutableData *)self initWithCapacity: [string length] / 3];
	self = [(OFMutableData *)self initWithCapacity: string.length / 3];

	@try {
		if (!of_base64_decode((OFMutableData *)self,
		    [string cStringWithEncoding: OF_STRING_ENCODING_ASCII],
		    [string cStringLengthWithEncoding:
		    OF_STRING_ENCODING_ASCII]))
			@throw [OFInvalidFormatException exception];
359
360
361
362
363
364
365
366
367


368
369
370

371
372
373
374
375
376
377
359
360
361
362
363
364
365


366
367
368
369

370
371
372
373
374
375
376
377







-
-
+
+


-
+








- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	void *pool = objc_autoreleasePoolPush();
	OFString *stringValue;

	@try {
		if (![[element name] isEqual: [self className]] ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
		if (![element.name isEqual: self.className] ||
		    ![element.namespace isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException exception];

		stringValue = [element stringValue];
		stringValue = element.stringValue;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithBase64EncodedString: stringValue];

444
445
446
447
448
449
450
451

452
453

454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473

474
475
476

477
478
479
480
481
482
483
444
445
446
447
448
449
450

451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469

470
471
472

473
474
475

476
477
478
479
480
481
482
483







-
+

-
+
















-
+


-
+


-
+







		return true;

	if (![object isKindOfClass: [OFData class]])
		return false;

	data = object;

	if ([data count] != _count || [data itemSize] != _itemSize)
	if (data.count != _count || data.itemSize != _itemSize)
		return false;
	if (memcmp([data items], _items, _count * _itemSize) != 0)
	if (memcmp(data.items, _items, _count * _itemSize) != 0)
		return false;

	return true;
}

- (of_comparison_result_t)compare: (id <OFComparing>)object
{
	OFData *data;
	int comparison;
	size_t count, minCount;

	if (![(id)object isKindOfClass: [OFData class]])
		@throw [OFInvalidArgumentException exception];

	data = (OFData *)object;

	if ([data itemSize] != _itemSize)
	if (data.itemSize != _itemSize)
		@throw [OFInvalidArgumentException exception];

	count = [data count];
	count = data.count;
	minCount = (_count > count ? count : _count);

	if ((comparison = memcmp(_items, [data items],
	if ((comparison = memcmp(_items, data.items,
	    minCount * _itemSize)) == 0) {
		if (_count > count)
			return OF_ORDERED_DESCENDING;
		if (_count < count)
			return OF_ORDERED_ASCENDING;

		return OF_ORDERED_SAME;
562
563
564
565
566
567
568
569

570
571
572

573
574
575
576
577
578

579
580
581
582
583
584
585
562
563
564
565
566
567
568

569
570
571

572
573
574
575
576
577

578
579
580
581
582
583
584
585







-
+


-
+





-
+







	const char *search;
	size_t searchLength;

	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length > _count)
		@throw [OFOutOfRangeException exception];

	if (data == nil || [data itemSize] != _itemSize)
	if (data == nil || data.itemSize != _itemSize)
		@throw [OFInvalidArgumentException exception];

	if ((searchLength = [data count]) == 0)
	if ((searchLength = data.count) == 0)
		return of_range(0, 0);

	if (searchLength > range.length)
		return of_range(OF_NOT_FOUND, 0);

	search = [data items];
	search = data.items;

	if (options & OF_DATA_SEARCH_BACKWARDS) {
		for (size_t i = range.length - searchLength;; i--) {
			if (memcmp(_items + i * _itemSize, search,
			    searchLength * _itemSize) == 0)
				return of_range(i, searchLength);

635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649







-
+







	OFXMLElement *element;

	if (_itemSize != 1)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();
	element = [OFXMLElement
	    elementWithName: [self className]
	    elementWithName: self.className
		  namespace: OF_SERIALIZATION_NS
		stringValue: of_base64_encode(_items, _count * _itemSize)];

	[element retain];

	objc_autoreleasePoolPop(pool);