ObjFW  Check-in [696bc0d890]

Overview
Comment:OFMutableString: Check more arguments for nil
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 696bc0d8907b20fdd07cf630ea25d4835ccebf9cf1251438f8caa2bb44bd98c9
User & Date: js on 2017-03-12 00:58:48
Other Links: manifest | tags
Context
2017-03-12
01:00
Fix setting shared localization for NULL locale check-in: f14a6e94e4 user: js tags: trunk
00:58
OFMutableString: Check more arguments for nil check-in: 696bc0d890 user: js tags: trunk
00:31
configure: Check if assert is buggy with -pedantic check-in: 7d9ac574a8 user: js tags: trunk
Changes

Modified src/OFMutableString.m from [39a9726c51] to [b4559a9fab].

521
522
523
524
525
526
527



528
529
530
531
532
533
534
{
	void *pool = objc_autoreleasePoolPush(), *pool2;
	const of_unichar_t *characters;
	const of_unichar_t *searchCharacters = [string characters];
	size_t searchLength = [string length];
	size_t replacementLength = [replacement length];




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

	if (searchLength > range.length) {
		objc_autoreleasePoolPop(pool);
		return;







>
>
>







521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
{
	void *pool = objc_autoreleasePoolPush(), *pool2;
	const of_unichar_t *characters;
	const of_unichar_t *searchCharacters = [string characters];
	size_t searchLength = [string length];
	size_t replacementLength = [replacement length];

	if (string == nil || replacement == nil)
		@throw [OFInvalidArgumentException exception];

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

	if (searchLength > range.length) {
		objc_autoreleasePoolPop(pool);
		return;

Modified src/OFMutableString_UTF8.m from [921a7c0237] to [7a27106bbd].

591
592
593
594
595
596
597



598
599
600
601
602
603
604
- (void)replaceCharactersInRange: (of_range_t)range
		      withString: (OFString*)replacement
{
	size_t start = range.location;
	size_t end = range.location + range.length;
	size_t newCStringLength, newLength;




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

	newLength = _s->length - range.length + [replacement length];

	if (_s->isUTF8) {
		start = of_string_utf8_get_position(_s->cString, start,







>
>
>







591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
- (void)replaceCharactersInRange: (of_range_t)range
		      withString: (OFString*)replacement
{
	size_t start = range.location;
	size_t end = range.location + range.length;
	size_t newCStringLength, newLength;

	if (replacement == nil)
		@throw [OFInvalidArgumentException exception];

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

	newLength = _s->length - range.length + [replacement length];

	if (_s->isUTF8) {
		start = of_string_utf8_get_position(_s->cString, start,
649
650
651
652
653
654
655



656
657
658
659
660
661
662
	const char *searchString = [string UTF8String];
	const char *replacementString = [replacement UTF8String];
	size_t searchLength = [string UTF8StringLength];
	size_t replacementLength = [replacement UTF8StringLength];
	size_t last, newCStringLength, newLength;
	char *newCString;




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

	if (_s->isUTF8) {
		range.location = of_string_utf8_get_position(_s->cString,
		    range.location, _s->cStringLength);







>
>
>







652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
	const char *searchString = [string UTF8String];
	const char *replacementString = [replacement UTF8String];
	size_t searchLength = [string UTF8StringLength];
	size_t replacementLength = [replacement UTF8StringLength];
	size_t last, newCStringLength, newLength;
	char *newCString;

	if (string == nil || replacement == nil)
		@throw [OFInvalidArgumentException exception];

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

	if (_s->isUTF8) {
		range.location = of_string_utf8_get_position(_s->cString,
		    range.location, _s->cStringLength);