ObjFW  Check-in [d2567246f9]

Overview
Comment:Nicer overflow check in -[decimalValue].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d2567246f9e96d968366b5b082bd1144568dd5a7935ec811555cc5bd00d19d21
User & Date: js on 2010-12-26 02:47:44
Other Links: manifest | tags
Context
2010-12-26
23:53
Update buildsys. check-in: 30e655261a user: js tags: trunk
02:47
Nicer overflow check in -[decimalValue]. check-in: d2567246f9 user: js tags: trunk
00:01
Don't use strlen in -[appendCString:withLength:].
This might cause trouble if the string is not terminated.
check-in: 05207af0f6 user: js tags: trunk
Changes

Modified src/OFString.m from [633e178038] to [03fe30d505].

972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
	intmax_t num = 0;

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

	for (; i < length; i++) {
		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;








<
|
|



|







972
973
974
975
976
977
978

979
980
981
982
983
984
985
986
987
988
989
990
991
	intmax_t num = 0;

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

	for (; i < length; i++) {
		if (string[i] >= '0' && string[i] <= '9') {

			if (INTMAX_MAX / 10 < num ||
			    INTMAX_MAX - num * 10 < string[i] - '0')
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			num = (num * 10) + (string[i] - '0');
		} else
			@throw [OFInvalidEncodingException newWithClass: isa];
	}

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