ObjFW  Check-in [8afa16c9e9]

Overview
Comment:Fix two more FIXMEs.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8afa16c9e98f360bf459074a68a2ddbab47282d0ab2689d6f8d134709f7b3447
User & Date: js on 2009-11-14 12:46:17
Other Links: manifest | tags
Context
2009-11-15
00:59
Update buildsys. check-in: 76f03bb012 user: js tags: trunk
2009-11-14
12:46
Fix two more FIXMEs. check-in: 8afa16c9e9 user: js tags: trunk
12:17
New solution for TLS key destructors that works on any OS. check-in: 12101c192f user: js tags: trunk
Changes

Modified src/OFString.m from [dcfcc7e490] to [fa163f325d].

800
801
802
803
804
805
806
807
808
809
810
811









812
813
814
815
816
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
832
833
834
835
836
837
838


839
840

841
842

843
844

845
846





847
848
849
850
851
852
853
800
801
802
803
804
805
806

807



808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828

829
830
831
832
833
834
835
836
837
838
839
840
841

842
843
844
845

846
847

848
849

850
851
852
853
854
855
856
857
858
859
860
861
862
863
864







-

-
-
-
+
+
+
+
+
+
+
+
+












-
+












-

+
+

-
+

-
+

-
+


+
+
+
+
+







{
	int i = 0;
	intmax_t num = 0;

	if (string[0] == '-')
		i++;

	/* FIXME: Add overflow check */
	for (; i < length; i++) {
		if (string[i] >= '0' && string[i] <= '9')
			num = (num * 10) + (string[i] - '0');
		else
		if (string[i] >= '0' && string[i] <= '9') {
			intmax_t newnum = (num * 10) + (string[i] - '0');

			if (newnum < num)
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			num = newnum;
		} else
			@throw [OFInvalidEncodingException newWithClass: isa];
	}

	if (string[0] == '-')
		num *= -1;

	return num;
}

- (intmax_t)hexadecimalValueAsInteger
{
	int i = 0;
	intmax_t num = 0;
	uintmax_t num = 0;

	if (length == 0)
		return 0;

	if (length >= 2 && string[0] == '0' && string[1] == 'x')
		i = 2;
	else if (length >= 1 && (string[0] == 'x' || string[0] == '$'))
		i = 1;

	if (i == length)
		@throw [OFInvalidEncodingException newWithClass: isa];

	/* FIXME: Add overflow check */
	for (; i < length; i++) {
		uintmax_t newnum;

		if (string[i] >= '0' && string[i] <= '9')
			num = (num << 4) | (string[i] - '0');
			newnum = (num << 4) | (string[i] - '0');
		else if (string[i] >= 'A' && string[i] <= 'F')
			num = (num << 4) | (string[i] - 'A' + 10);
			newnum = (num << 4) | (string[i] - 'A' + 10);
		else if (string[i] >= 'a' && string[i] <= 'f')
			num = (num << 4) | (string[i] - 'a' + 10);
			newnum = (num << 4) | (string[i] - 'a' + 10);
		else
			@throw [OFInvalidEncodingException newWithClass: isa];

		if (newnum < num)
			@throw [OFOutOfRangeException newWithClass: isa];

		num = newnum;
	}

	return num;
}

- setToCString: (const char*)str
{

Modified tests/OFString.m from [5db36dc58d] to [ade3ad2d15].

193
194
195
196
197
198
199

200
201
202
203
204
205
206
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207







+







	    [[a objectAtIndex: i++] isEqual: @""] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"] &&
	    [[a objectAtIndex: i++] isEqual: @""] &&
	    [[a objectAtIndex: i++] isEqual: @""])

	TEST(@"-[decimalValueAsInteger]",
	    [@"1234" decimalValueAsInteger] == 1234 &&
	    [@"-500" decimalValueAsInteger] == -500 &&
	    [@"" decimalValueAsInteger] == 0)

	TEST(@"-[hexadecimalValueAsInteger]",
	    [@"123f" hexadecimalValueAsInteger] == 0x123f &&
	    [@"0xABcd" hexadecimalValueAsInteger] == 0xABCD &&
	    [@"xbCDE" hexadecimalValueAsInteger] == 0xBCDE &&
	    [@"$CdEf" hexadecimalValueAsInteger] == 0xCDEF &&
218
219
220
221
222
223
224












225
226
227
228
229
230
231
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244







+
+
+
+
+
+
+
+
+
+
+
+







	    [@"0xABCDEFG" hexadecimalValueAsInteger])
	EXPECT_EXCEPTION(@"Detect invalid chars in "
	    @"-[hexadecimalValueAsInteger] #2", OFInvalidEncodingException,
	    [@"0x" hexadecimalValueAsInteger])
	EXPECT_EXCEPTION(@"Detect invalid chars in "
	    @"-[hexadecimalValueAsInteger] #3", OFInvalidEncodingException,
	    [@"$" hexadecimalValueAsInteger])

	EXPECT_EXCEPTION(@"Detect out of range in -[decimalValueAsInteger",
	    OFOutOfRangeException,
	    [@"12345678901234567890123456789012345678901234567890"
	     @"12345678901234567890123456789012345678901234567890"
	    decimalValueAsInteger])

	EXPECT_EXCEPTION(@"Detect out of range in -[hexadecilamValueAsInteger",
	    OFOutOfRangeException,
	    [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
	     @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
	    hexadecimalValueAsInteger])

	TEST(@"-[md5Hash]", [[@"asdfoobar" md5Hash]
	    isEqual: @"184dce2ec49b5422c7cfd8728864db4c"])

	TEST(@"-[sha1Hash]", [[@"asdfoobar" sha1Hash]
	    isEqual: @"f5f81ac0a8b5cbfdc4585ec1ad32e7b3a12b9b49"])