ObjFW  Diff

Differences From Artifact [d8bc2c6ad4]:

To Artifact [36fe618ac5]:


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
	    ((uint64_t)buffer[6] << 8) | buffer[7];
}

static size_t
parseArray(const uint8_t *buffer, size_t length, id *object, size_t count)
{
	void *pool;
	size_t i, pos;

	/*
	 * Don't use capacity! For data and strings, this is safe, as we can
	 * check if we still have enough bytes left. For an array however, we
	 * can't know this, as every child can be more than one byte.
	 */
	*object = [OFMutableArray array];
	pos = 0;

	for (i = 0; i < count; i++) {
		id child;
		size_t childLength;

		pool = objc_autoreleasePoolPush();

		childLength = parseObject(buffer + pos, length - pos, &child);
		if (childLength == 0 || child == nil) {







|







<

|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
	    ((uint64_t)buffer[6] << 8) | buffer[7];
}

static size_t
parseArray(const uint8_t *buffer, size_t length, id *object, size_t count)
{
	void *pool;
	size_t pos = 0;

	/*
	 * Don't use capacity! For data and strings, this is safe, as we can
	 * check if we still have enough bytes left. For an array however, we
	 * can't know this, as every child can be more than one byte.
	 */
	*object = [OFMutableArray array];


	for (size_t i = 0; i < count; i++) {
		id child;
		size_t childLength;

		pool = objc_autoreleasePoolPush();

		childLength = parseObject(buffer + pos, length - pos, &child);
		if (childLength == 0 || child == nil) {
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 pos;
}

static size_t
parseTable(const uint8_t *buffer, size_t length, id *object, size_t count)
{
	void *pool;
	size_t i, pos;

	/*
	 * Don't use capacity! For data and strings, this is safe, as we can
	 * check if we still have enough bytes left. For a dictionary however,
	 * we can't know this, as every key / value can be more than one byte.
	 */
	*object = [OFMutableDictionary dictionary];
	pos = 0;

	for (i = 0; i < count; i++) {
		id key, value;
		size_t keyLength, valueLength;

		pool = objc_autoreleasePoolPush();

		keyLength = parseObject(buffer + pos, length - pos, &key);
		if (keyLength == 0 || key == nil) {







|







<

|







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
112
	return pos;
}

static size_t
parseTable(const uint8_t *buffer, size_t length, id *object, size_t count)
{
	void *pool;
	size_t pos = 0;

	/*
	 * Don't use capacity! For data and strings, this is safe, as we can
	 * check if we still have enough bytes left. For a dictionary however,
	 * we can't know this, as every key / value can be more than one byte.
	 */
	*object = [OFMutableDictionary dictionary];


	for (size_t i = 0; i < count; i++) {
		id key, value;
		size_t keyLength, valueLength;

		pool = objc_autoreleasePoolPush();

		keyLength = parseObject(buffer + pos, length - pos, &key);
		if (keyLength == 0 || key == nil) {
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

	return pos;
}

static size_t
parseObject(const uint8_t *buffer, size_t length, id *object)
{
	size_t i, count;
	int8_t type;
	OFDataArray *data;

	if (length < 1)
		goto error;

	/* positive fixint */







|







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

	return pos;
}

static size_t
parseObject(const uint8_t *buffer, size_t length, id *object)
{
	size_t count;
	int8_t type;
	OFDataArray *data;

	if (length < 1)
		goto error;

	/* positive fixint */
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
			uint8_t u8[4];
			float f;
		} f;

		if (length < 5)
			goto error;

		for (i = 0; i < 4; i++)
			f.u8[i] = buffer[i + 1];

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

		if (length < 9)
			goto error;

		for (i = 0; i < 8; i++)
			d.u8[i] = buffer[i + 1];

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







|













|







238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
			uint8_t u8[4];
			float f;
		} f;

		if (length < 5)
			goto error;

		for (size_t i = 0; i < 4; i++)
			f.u8[i] = buffer[i + 1];

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

		if (length < 9)
			goto error;

		for (size_t i = 0; i < 8; i++)
			d.u8[i] = buffer[i + 1];

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