ObjFW  Check-in [e0459c419c]

Overview
Comment:Reduce usage of unions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e0459c419cca642ffb041ce56ce4c30385093fb1fbca83f707902ee3c67772c6
User & Date: js on 2020-04-19 14:52:59
Other Links: manifest | tags
Context
2020-04-19
15:24
Several documentation improvements check-in: f27905c199 user: js tags: trunk
14:52
Reduce usage of unions check-in: e0459c419c user: js tags: trunk
14:07
Update buildsys check-in: dcebb980d6 user: js tags: trunk
Changes

Modified src/OFColor.m from [c54ddadacf] to [cae3bcbbaf].

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;
	union {
		float f;
		unsigned char b[sizeof(float)];
	} f;

	OF_HASH_INIT(hash);

	f.f = OF_BSWAP_FLOAT_IF_LE(_red);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, f.b[i]);

	f.f = OF_BSWAP_FLOAT_IF_LE(_green);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, f.b[i]);

	f.f = OF_BSWAP_FLOAT_IF_LE(_blue);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, f.b[i]);

	f.f = OF_BSWAP_FLOAT_IF_LE(_alpha);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, f.b[i]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (void)getRed: (float *)red







<
|
<
<



|

|

|

|

|

|

|

|







82
83
84
85
86
87
88

89


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;

	float tmp;



	OF_HASH_INIT(hash);

	tmp = OF_BSWAP_FLOAT_IF_LE(_red);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, ((char *)&tmp)[i]);

	tmp = OF_BSWAP_FLOAT_IF_LE(_green);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, ((char *)&tmp)[i]);

	tmp = OF_BSWAP_FLOAT_IF_LE(_blue);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, ((char *)&tmp)[i]);

	tmp = OF_BSWAP_FLOAT_IF_LE(_alpha);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OF_HASH_ADD(hash, ((char *)&tmp)[i]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (void)getRed: (float *)red

Modified src/OFData+MessagePackValue.m from [95748cc907] to [caaaf51219].

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
		if (length < 9)
			@throw [OFTruncatedDataException exception];

		*object = [OFNumber numberWithInt64: readUInt64(buffer + 1)];
		return 9;
	/* Floating point */
	case 0xCA:; /* float 32 */
		union {
			unsigned char u8[4];
			float f;
		} f;

		if (length < 5)
			@throw [OFTruncatedDataException exception];

		memcpy(&f.u8, buffer + 1, 4);

		*object = [OFNumber numberWithFloat: OF_BSWAP_FLOAT_IF_LE(f.f)];
		return 5;
	case 0xCB:; /* float 64 */
		union {
			unsigned char u8[8];
			double d;
		} d;

		if (length < 9)
			@throw [OFTruncatedDataException exception];

		memcpy(&d.u8, buffer + 1, 8);

		*object = [OFNumber numberWithDouble:
		    OF_BSWAP_DOUBLE_IF_LE(d.d)];
		return 9;
	/* nil */
	case 0xC0:
		*object = [OFNull null];
		return 1;
	/* false */
	case 0xC2:







<
<
|
<




|

|


<
<
|
<




|

|
<







276
277
278
279
280
281
282


283

284
285
286
287
288
289
290
291
292


293

294
295
296
297
298
299
300

301
302
303
304
305
306
307
		if (length < 9)
			@throw [OFTruncatedDataException exception];

		*object = [OFNumber numberWithInt64: readUInt64(buffer + 1)];
		return 9;
	/* Floating point */
	case 0xCA:; /* float 32 */


		float f;


		if (length < 5)
			@throw [OFTruncatedDataException exception];

		memcpy(&f, buffer + 1, 4);

		*object = [OFNumber numberWithFloat: OF_BSWAP_FLOAT_IF_LE(f)];
		return 5;
	case 0xCB:; /* float 64 */


		double d;


		if (length < 9)
			@throw [OFTruncatedDataException exception];

		memcpy(&d, buffer + 1, 8);

		*object = [OFNumber numberWithDouble: OF_BSWAP_DOUBLE_IF_LE(d)];

		return 9;
	/* nil */
	case 0xC0:
		*object = [OFNull null];
		return 1;
	/* false */
	case 0xC2:

Modified src/OFDate.m from [ab9874f31d] to [b94395832f].

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		union {
			double d;
			uint64_t u;
		} d;

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

		d.u = (uint64_t)element.hexadecimalValue;
		d.u = OF_BSWAP64_IF_LE(d.u);
		_seconds = OF_BSWAP_DOUBLE_IF_LE(d.d);


		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}








<
<
<
<





<
<
|
>







336
337
338
339
340
341
342




343
344
345
346
347


348
349
350
351
352
353
354
355
356

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();





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



		_seconds = OF_BSWAP_DOUBLE_IF_LE(OF_INT_TO_DOUBLE_RAW(
		    OF_BSWAP64_IF_LE(element.hexadecimalValue)));

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;
	union {
		double d;
		uint8_t b[sizeof(double)];
	} d;

	d.d = OF_BSWAP_DOUBLE_IF_BE(_seconds);

	OF_HASH_INIT(hash);

	for (size_t i = 0; i < sizeof(double); i++)
		OF_HASH_ADD(hash, d.b[i]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (id)copy







<
|
<
<

|

|


|







374
375
376
377
378
379
380

381


382
383
384
385
386
387
388
389
390
391
392
393
394
395

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;

	double tmp;



	OF_HASH_INIT(hash);

	tmp = OF_BSWAP_DOUBLE_IF_BE(_seconds);

	for (size_t i = 0; i < sizeof(double); i++)
		OF_HASH_ADD(hash, ((char *)&tmp)[i]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (id)copy
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444

445
446
447
448
449
450
451
	return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"];
}

- (OFXMLElement *)XMLElementBySerializing
{
	void *pool = objc_autoreleasePoolPush();
	OFXMLElement *element;
	union {
		double d;
		uint64_t u;
	} d;

	element = [OFXMLElement elementWithName: self.className
				      namespace: OF_SERIALIZATION_NS];

	d.d = OF_BSWAP_DOUBLE_IF_LE(_seconds);
	element.stringValue =
	    [OFString stringWithFormat: @"%016" PRIx64, OF_BSWAP64_IF_LE(d.u)];


	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}







<
<
<
<




<
|
|
>







419
420
421
422
423
424
425




426
427
428
429

430
431
432
433
434
435
436
437
438
439
	return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"];
}

- (OFXMLElement *)XMLElementBySerializing
{
	void *pool = objc_autoreleasePoolPush();
	OFXMLElement *element;





	element = [OFXMLElement elementWithName: self.className
				      namespace: OF_SERIALIZATION_NS];


	element.stringValue = [OFString stringWithFormat: @"%016" PRIx64,
	    OF_BSWAP64_IF_LE(OF_DOUBLE_TO_INT_RAW(OF_BSWAP_DOUBLE_IF_LE(
	    _seconds)))];

	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

Modified src/OFLocale.m from [0b5d50eb1d] to [aa7c2af69a].

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
		if (GetVar("Language", buffer, sizeof(buffer), 0) > 0)
			_language = [[OFString alloc]
			    initWithCString: buffer
				   encoding: _encoding];

		if ((locale = OpenLocale(NULL)) != NULL) {
			@try {
				union {
					uint32_t u32;
					char c[4];
				} territory;
				size_t length;

				territory.u32 =
				    OF_BSWAP32_IF_LE(locale->loc_CountryCode);

				for (length = 0; length < 4; length++)
					if (territory.c[length] == 0)
						break;

				_territory = [[OFString alloc]
				    initWithCString: territory.c
					   encoding: _encoding
					     length: length];
			} @finally {







<
|
<
<


|



|







451
452
453
454
455
456
457

458


459
460
461
462
463
464
465
466
467
468
469
470
471
472
		if (GetVar("Language", buffer, sizeof(buffer), 0) > 0)
			_language = [[OFString alloc]
			    initWithCString: buffer
				   encoding: _encoding];

		if ((locale = OpenLocale(NULL)) != NULL) {
			@try {

				uint32_t territory;


				size_t length;

				territory =
				    OF_BSWAP32_IF_LE(locale->loc_CountryCode);

				for (length = 0; length < 4; length++)
					if (((char *)territory)[length] == 0)
						break;

				_territory = [[OFString alloc]
				    initWithCString: territory.c
					   encoding: _encoding
					     length: length];
			} @finally {

Modified src/OFMD5Hash.h from [afbdcd7e31] to [7314ebcbd4].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@interface OFMD5Hash: OFObject <OFCryptoHash>
{
	OFSecureData *_iVarsData;
	struct of_md5_hash_ivars {
		uint32_t state[4];
		uint64_t bits;
		union of_md5_hash_buffer {
			uint8_t bytes[64];
			uint32_t words[16];
		} buffer;
		size_t bufferLength;
	} *_iVars;
	bool _allowsSwappableMemory;
	bool _calculated;
}
@end

OF_ASSUME_NONNULL_END







|










30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@interface OFMD5Hash: OFObject <OFCryptoHash>
{
	OFSecureData *_iVarsData;
	struct of_md5_hash_ivars {
		uint32_t state[4];
		uint64_t bits;
		union of_md5_hash_buffer {
			unsigned char bytes[64];
			uint32_t words[16];
		} buffer;
		size_t bufferLength;
	} *_iVars;
	bool _allowsSwappableMemory;
	bool _calculated;
}
@end

OF_ASSUME_NONNULL_END

Modified src/OFNumber.m from [5a67a624f2] to [f96cb2d4be].

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581


582
583
584
585
586
587
588
			 */
			_type = OF_NUMBER_TYPE_UINTMAX;
			_value.uIntMax = element.decimalValue;
		} else if ([typeString isEqual: @"signed"]) {
			_type = OF_NUMBER_TYPE_INTMAX;
			_value.intMax = element.decimalValue;
		} else if ([typeString isEqual: @"float"]) {
			union {
				float f;
				uint32_t u;
			} f;

			f.u = OF_BSWAP32_IF_LE(
			    (uint32_t)element.hexadecimalValue);

			_type = OF_NUMBER_TYPE_FLOAT;
			_value.float_ = OF_BSWAP_FLOAT_IF_LE(f.f);
		} else if ([typeString isEqual: @"double"]) {
			union {
				double d;
				uint64_t u;
			} d;

			d.u = OF_BSWAP64_IF_LE(
			    (uint64_t)element.hexadecimalValue);

			_type = OF_NUMBER_TYPE_DOUBLE;
			_value.double_ = OF_BSWAP_DOUBLE_IF_LE(d.d);


		} else
			@throw [OFInvalidArgumentException exception];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;







<
<
<
<
<
<
<
<

|
<
<
<
<
<
|
<
|
|

|
>
>







554
555
556
557
558
559
560








561
562





563

564
565
566
567
568
569
570
571
572
573
574
575
576
			 */
			_type = OF_NUMBER_TYPE_UINTMAX;
			_value.uIntMax = element.decimalValue;
		} else if ([typeString isEqual: @"signed"]) {
			_type = OF_NUMBER_TYPE_INTMAX;
			_value.intMax = element.decimalValue;
		} else if ([typeString isEqual: @"float"]) {








			_type = OF_NUMBER_TYPE_FLOAT;
			_value.float_ = OF_BSWAP_FLOAT_IF_LE(





			    OF_INT_TO_FLOAT_RAW(OF_BSWAP32_IF_LE(

			    (uint32_t)element.hexadecimalValue)));
		} else if ([typeString isEqual: @"double"]) {
			_type = OF_NUMBER_TYPE_DOUBLE;
			_value.double_ = OF_BSWAP_DOUBLE_IF_LE(
			    OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(
			    (uint64_t)element.hexadecimalValue)));
		} else
			@throw [OFInvalidArgumentException exception];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
				type &= ~OF_NUMBER_TYPE_FLOAT;
		}
	}

	OF_HASH_INIT(hash);

	if (type & OF_NUMBER_TYPE_FLOAT) {
		union {
			double d;
			uint8_t b[sizeof(double)];
		} d;

		if (isnan(self.doubleValue))
			return 0;

		d.d = OF_BSWAP_DOUBLE_IF_BE(self.doubleValue);

		for (uint_fast8_t i = 0; i < sizeof(double); i++)
			OF_HASH_ADD(hash, d.b[i]);
	} else if (type & OF_NUMBER_TYPE_SIGNED) {
		intmax_t v = self.intMaxValue * -1;

		while (v != 0) {
			OF_HASH_ADD(hash, v & 0xFF);
			v >>= 8;
		}







<
|
<
<




|


|







1059
1060
1061
1062
1063
1064
1065

1066


1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
				type &= ~OF_NUMBER_TYPE_FLOAT;
		}
	}

	OF_HASH_INIT(hash);

	if (type & OF_NUMBER_TYPE_FLOAT) {

		double d;



		if (isnan(self.doubleValue))
			return 0;

		d = OF_BSWAP_DOUBLE_IF_BE(self.doubleValue);

		for (uint_fast8_t i = 0; i < sizeof(double); i++)
			OF_HASH_ADD(hash, ((char *)&d)[i]);
	} else if (type & OF_NUMBER_TYPE_SIGNED) {
		intmax_t v = self.intMaxValue * -1;

		while (v != 0) {
			OF_HASH_ADD(hash, v & 0xFF);
			v >>= 8;
		}
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
	case OF_NUMBER_TYPE_INT8:
	case OF_NUMBER_TYPE_INT16:
	case OF_NUMBER_TYPE_INT32:
	case OF_NUMBER_TYPE_INT64:
	case OF_NUMBER_TYPE_SSIZE:
	case OF_NUMBER_TYPE_INTMAX:
	case OF_NUMBER_TYPE_PTRDIFF:
	case OF_NUMBER_TYPE_INTPTR:;
		[element addAttributeWithName: @"type"
				  stringValue: @"signed"];
		break;
	case OF_NUMBER_TYPE_FLOAT:;
		union {
			float f;
			uint32_t u;
		} f;

		f.f = OF_BSWAP_FLOAT_IF_LE(_value.float_);

		[element addAttributeWithName: @"type"
				  stringValue: @"float"];
		element.stringValue =
		    [OFString stringWithFormat: @"%08" PRIx32,
						OF_BSWAP32_IF_LE(f.u)];


		break;
	case OF_NUMBER_TYPE_DOUBLE:;
		union {
			double d;
			uint64_t u;
		} d;

		d.d = OF_BSWAP_DOUBLE_IF_LE(_value.double_);

		[element addAttributeWithName: @"type"
				  stringValue: @"double"];
		element.stringValue =
		    [OFString stringWithFormat: @"%016" PRIx64,
						OF_BSWAP64_IF_LE(d.u)];


		break;
	default:
		@throw [OFInvalidFormatException exception];
	}

	[element retain];







|



|
<
<
<
<
<
<
<


<
|
|
>


|
<
<
<
<
<
<
<


|
|
|
>







1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210







1211
1212

1213
1214
1215
1216
1217
1218







1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
	case OF_NUMBER_TYPE_INT8:
	case OF_NUMBER_TYPE_INT16:
	case OF_NUMBER_TYPE_INT32:
	case OF_NUMBER_TYPE_INT64:
	case OF_NUMBER_TYPE_SSIZE:
	case OF_NUMBER_TYPE_INTMAX:
	case OF_NUMBER_TYPE_PTRDIFF:
	case OF_NUMBER_TYPE_INTPTR:
		[element addAttributeWithName: @"type"
				  stringValue: @"signed"];
		break;
	case OF_NUMBER_TYPE_FLOAT:







		[element addAttributeWithName: @"type"
				  stringValue: @"float"];

		element.stringValue = [OFString stringWithFormat: @"%08" PRIx32,
		    OF_BSWAP32_IF_LE(OF_FLOAT_TO_INT_RAW(OF_BSWAP_FLOAT_IF_LE(
		    _value.float_)))];

		break;
	case OF_NUMBER_TYPE_DOUBLE:







		[element addAttributeWithName: @"type"
				  stringValue: @"double"];
		element.stringValue = [OFString
		    stringWithFormat: @"%016" PRIx64,
		    OF_BSWAP64_IF_LE(OF_DOUBLE_TO_INT_RAW(OF_BSWAP_DOUBLE_IF_LE(
		    _value.double_)))];

		break;
	default:
		@throw [OFInvalidFormatException exception];
	}

	[element retain];

Modified src/OFRIPEMD160Hash.h from [b0c573b36f] to [bd428762b3].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@interface OFRIPEMD160Hash: OFObject <OFCryptoHash>
{
	OFSecureData *_iVarsData;
	struct of_ripemd160_hash_ivars {
		uint32_t state[5];
		uint64_t bits;
		union of_ripemd160_hash_buffer {
			uint8_t bytes[64];
			uint32_t words[16];
		} buffer;
		size_t bufferLength;
	} *_iVars;
	bool _allowsSwappableMemory;
	bool _calculated;
}
@end

OF_ASSUME_NONNULL_END







|










30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@interface OFRIPEMD160Hash: OFObject <OFCryptoHash>
{
	OFSecureData *_iVarsData;
	struct of_ripemd160_hash_ivars {
		uint32_t state[5];
		uint64_t bits;
		union of_ripemd160_hash_buffer {
			unsigned char bytes[64];
			uint32_t words[16];
		} buffer;
		size_t bufferLength;
	} *_iVars;
	bool _allowsSwappableMemory;
	bool _calculated;
}
@end

OF_ASSUME_NONNULL_END

Modified src/OFSHA1Hash.h from [812276bc67] to [bd4ba48e95].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@interface OFSHA1Hash: OFObject <OFCryptoHash>
{
	OFSecureData *_iVarsData;
	struct of_sha1_hash_ivars {
		uint32_t state[5];
		uint64_t bits;
		union of_sha1_hash_buffer {
			uint8_t bytes[64];
			uint32_t words[80];
		} buffer;
		size_t bufferLength;
	} *_iVars;
	bool _allowsSwappableMemory;
	bool _calculated;
}
@end

OF_ASSUME_NONNULL_END







|










30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@interface OFSHA1Hash: OFObject <OFCryptoHash>
{
	OFSecureData *_iVarsData;
	struct of_sha1_hash_ivars {
		uint32_t state[5];
		uint64_t bits;
		union of_sha1_hash_buffer {
			unsigned char bytes[64];
			uint32_t words[80];
		} buffer;
		size_t bufferLength;
	} *_iVars;
	bool _allowsSwappableMemory;
	bool _calculated;
}
@end

OF_ASSUME_NONNULL_END

Modified src/OFSHA224Or256Hash.h from [9b410449c3] to [deb793f9c1].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@private
	OFSecureData *_iVarsData;
@protected
	struct of_sha224_or_256_hash_ivars {
		uint32_t state[8];
		uint64_t bits;
		union of_sha224_or_256_hash_buffer {
			uint8_t bytes[64];
			uint32_t words[64];
		} buffer;
		size_t bufferLength;
	} *_iVars;
@private
	bool _allowsSwappableMemory;
	bool _calculated;
	OF_RESERVE_IVARS(4)
}
@end

OF_ASSUME_NONNULL_END







|












31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@private
	OFSecureData *_iVarsData;
@protected
	struct of_sha224_or_256_hash_ivars {
		uint32_t state[8];
		uint64_t bits;
		union of_sha224_or_256_hash_buffer {
			unsigned char bytes[64];
			uint32_t words[64];
		} buffer;
		size_t bufferLength;
	} *_iVars;
@private
	bool _allowsSwappableMemory;
	bool _calculated;
	OF_RESERVE_IVARS(4)
}
@end

OF_ASSUME_NONNULL_END

Modified src/OFSHA384Or512Hash.h from [b0f0d3732f] to [e5381155b9].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@private
	OFSecureData *_iVarsData;
@protected
	struct of_sha384_or_512_hash_ivars {
		uint64_t state[8];
		uint64_t bits[2];
		union of_sha384_or_512_hash_buffer {
			uint8_t bytes[128];
			uint64_t words[80];
		} buffer;
		size_t bufferLength;
	} *_iVars;
@private
	bool _allowsSwappableMemory;
	bool _calculated;
	OF_RESERVE_IVARS(4)
}
@end

OF_ASSUME_NONNULL_END







|












31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@private
	OFSecureData *_iVarsData;
@protected
	struct of_sha384_or_512_hash_ivars {
		uint64_t state[8];
		uint64_t bits[2];
		union of_sha384_or_512_hash_buffer {
			unsigned char bytes[128];
			uint64_t words[80];
		} buffer;
		size_t bufferLength;
	} *_iVars;
@private
	bool _allowsSwappableMemory;
	bool _calculated;
	OF_RESERVE_IVARS(4)
}
@end

OF_ASSUME_NONNULL_END

Modified src/OFTarArchive.m from [fe80dcdcf2] to [9fc8cae7a2].

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
			_mode = OF_TAR_ARCHIVE_MODE_WRITE;
		else if ([mode isEqual: @"a"])
			_mode = OF_TAR_ARCHIVE_MODE_APPEND;
		else
			@throw [OFInvalidArgumentException exception];

		if (_mode == OF_TAR_ARCHIVE_MODE_APPEND) {
			union {
				char c[1024];
				uint32_t u32[1024 / sizeof(uint32_t)];
			} buffer;
			bool empty = true;

			if (![_stream isKindOfClass: [OFSeekableStream class]])
				@throw [OFInvalidArgumentException exception];

			[(OFSeekableStream *)_stream seekToOffset: -1024
							   whence: SEEK_END];
			[_stream readIntoBuffer: buffer.c
				    exactLength: 1024];

			for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++)
				if (buffer.u32[i] != 0)
					empty = false;

			if (!empty)
				@throw [OFInvalidFormatException exception];

			[(OFSeekableStream *)stream seekToOffset: -1024
							  whence: SEEK_END];







<
<
|
<







|



|







96
97
98
99
100
101
102


103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
			_mode = OF_TAR_ARCHIVE_MODE_WRITE;
		else if ([mode isEqual: @"a"])
			_mode = OF_TAR_ARCHIVE_MODE_APPEND;
		else
			@throw [OFInvalidArgumentException exception];

		if (_mode == OF_TAR_ARCHIVE_MODE_APPEND) {


			uint32_t buffer[1024 / sizeof(uint32_t)];

			bool empty = true;

			if (![_stream isKindOfClass: [OFSeekableStream class]])
				@throw [OFInvalidArgumentException exception];

			[(OFSeekableStream *)_stream seekToOffset: -1024
							   whence: SEEK_END];
			[_stream readIntoBuffer: buffer
				    exactLength: 1024];

			for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++)
				if (buffer[i] != 0)
					empty = false;

			if (!empty)
				@throw [OFInvalidFormatException exception];

			[(OFSeekableStream *)stream seekToOffset: -1024
							  whence: SEEK_END];
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

	[super dealloc];
}

- (OFTarArchiveEntry *)nextEntry
{
	OFTarArchiveEntry *entry;
	union {
		unsigned char c[512];
		uint32_t u32[512 / sizeof(uint32_t)];
	} buffer;
	bool empty = true;

	if (_mode != OF_TAR_ARCHIVE_MODE_READ)
		@throw [OFInvalidArgumentException exception];

	[(OFTarArchiveFileReadStream *)_lastReturnedStream of_skip];
	@try {
		[_lastReturnedStream close];
	} @catch (OFNotOpenException *e) {
		/* Might have already been closed by the user - that's fine. */
	}
	[_lastReturnedStream release];
	_lastReturnedStream = nil;

	if (_stream.atEndOfStream)
		return nil;

	[_stream readIntoBuffer: buffer.c
		    exactLength: 512];

	for (size_t i = 0; i < 512 / sizeof(uint32_t); i++)
		if (buffer.u32[i] != 0)
			empty = false;

	if (empty) {
		[_stream readIntoBuffer: buffer.c
			    exactLength: 512];

		for (size_t i = 0; i < 512 / sizeof(uint32_t); i++)
			if (buffer.u32[i] != 0)
				@throw [OFInvalidFormatException exception];

		return nil;
	}

	entry = [[[OFTarArchiveEntry alloc]
	    of_initWithHeader: buffer.c
		     encoding: _encoding] autorelease];

	_lastReturnedStream = [[OFTarArchiveFileReadStream alloc]
	    of_initWithStream: _stream
			entry: entry];

	return entry;







<
<
|
<

















|



|



|



|






|







161
162
163
164
165
166
167


168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

	[super dealloc];
}

- (OFTarArchiveEntry *)nextEntry
{
	OFTarArchiveEntry *entry;


	uint32_t buffer[512 / sizeof(uint32_t)];

	bool empty = true;

	if (_mode != OF_TAR_ARCHIVE_MODE_READ)
		@throw [OFInvalidArgumentException exception];

	[(OFTarArchiveFileReadStream *)_lastReturnedStream of_skip];
	@try {
		[_lastReturnedStream close];
	} @catch (OFNotOpenException *e) {
		/* Might have already been closed by the user - that's fine. */
	}
	[_lastReturnedStream release];
	_lastReturnedStream = nil;

	if (_stream.atEndOfStream)
		return nil;

	[_stream readIntoBuffer: buffer
		    exactLength: 512];

	for (size_t i = 0; i < 512 / sizeof(uint32_t); i++)
		if (buffer[i] != 0)
			empty = false;

	if (empty) {
		[_stream readIntoBuffer: buffer
			    exactLength: 512];

		for (size_t i = 0; i < 512 / sizeof(uint32_t); i++)
			if (buffer[i] != 0)
				@throw [OFInvalidFormatException exception];

		return nil;
	}

	entry = [[[OFTarArchiveEntry alloc]
	    of_initWithHeader: (unsigned char *)buffer
		     encoding: _encoding] autorelease];

	_lastReturnedStream = [[OFTarArchiveFileReadStream alloc]
	    of_initWithStream: _stream
			entry: entry];

	return entry;

Modified src/macros.h from [798f22e9e5] to [0ec579f5ac].

548
549
550
551
552
553
554
555
556
557
558




559



560



561
562

563




564
565

566


567






568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# define OF_BSWAP64(i) \
    (__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
#else
# define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
# define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
# define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
#endif

static OF_INLINE float OF_CONST_FUNC
OF_BSWAP_FLOAT(float f)
{




	union {



		float f;



		uint32_t i;
	} u;






	u.f = f;
	u.i = OF_BSWAP32(u.i);




	return u.f;






}

static OF_INLINE double OF_CONST_FUNC
OF_BSWAP_DOUBLE(double d)
{
	union {
		double d;
		uint64_t i;
	} u;

	u.d = d;
	u.i = OF_BSWAP64(u.i);

	return u.d;
}

#ifdef OF_BIG_ENDIAN
# define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
# define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
# define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
# define OF_BSWAP16_IF_LE(i) (i)








|
|

>
>
>
>
|
>
>
>
|
>
>
>
|
|
>
|
>
>
>
>
|
|
>
|
>
>
|
>
>
>
>
>
>





<
<
<
<
|
<
<
<
<







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596




597




598
599
600
601
602
603
604
# define OF_BSWAP64(i) \
    (__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
#else
# define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
# define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
# define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
#endif

static OF_INLINE uint32_t
OF_FLOAT_TO_INT_RAW(float f)
{
	uint32_t ret;
	memcpy(&ret, &f, 4);
	return ret;
}

static OF_INLINE float
OF_INT_TO_FLOAT_RAW(uint32_t u32)
{
	float ret;
	memcpy(&ret, &u32, 4);
	return ret;
}

static OF_INLINE uint64_t
OF_DOUBLE_TO_INT_RAW(double d)
{
	uint64_t ret;
	memcpy(&ret, &d, 8);
	return ret;
}

static OF_INLINE double
OF_INT_TO_DOUBLE_RAW(uint64_t u64)
{
	double ret;
	memcpy(&ret, &u64, 8);
	return ret;
}

static OF_INLINE float OF_CONST_FUNC
OF_BSWAP_FLOAT(float f)
{
	return OF_INT_TO_FLOAT_RAW(OF_BSWAP32(OF_FLOAT_TO_INT_RAW(f)));
}

static OF_INLINE double OF_CONST_FUNC
OF_BSWAP_DOUBLE(double d)
{




	return OF_INT_TO_DOUBLE_RAW(OF_BSWAP64(OF_DOUBLE_TO_INT_RAW(d)));




}

#ifdef OF_BIG_ENDIAN
# define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
# define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
# define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
# define OF_BSWAP16_IF_LE(i) (i)