Skip to content

Out of range crash #19

@alariccole

Description

@alariccole

I was getting a range exception on longer strings. I fixed it by adding checks for range in the main class and its string category

//tomsmorphinglabel Line 342

            if (range.location + range.length < aString.length) {


                NSString *character = [aString substringWithRange:range];
                CGSize characterSize = CGSizeZero;

                if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    #ifdef PRECISE_FONT_METRICS
    #define CFAutomatedReferenceCount(CFAnyTypeRef, typeRef, CFCreateOrCopyFunction) CFAnyTypeRef typeRef = ((__bridge CFAnyTypeRef)CFBridgingRelease(CFCreateOrCopyFunction))
                    @autoreleasepool {
                        UIFont *font = attributionStage[NSFontAttributeName];
                        CFAutomatedReferenceCount(CTFontRef, fontRef, CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL));
                        CFAutomatedReferenceCount(CFAttributedStringRef, attributed, CFAttributedStringCreate(NULL, (__bridge CFStringRef)character, (__bridge CFDictionaryRef)@{(id)kCTFontAttributeName : (__bridge id)fontRef}));
                        CFAutomatedReferenceCount(CTFramesetterRef, framesetter, CTFramesetterCreateWithAttributedString(attributed));
                        CFAutomatedReferenceCount(CGPathRef, path, CGPathCreateWithRect(CGRectInfinite, NULL));
                        CFAutomatedReferenceCount(CTFrameRef, frame, CTFramesetterCreateFrame(framesetter, CFRangeMake(0, CFAttributedStringGetLength(attributed)), path, NULL));
                        NSArray *lines = (id)CTFrameGetLines(frame);
                        characterSize = CTLineGetBoundsWithOptions((__bridge CTLineRef)[lines firstObject], 0).size;
                    }
    #undef CFAutomatedReferenceCount
    #else
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
                    /* Quick and dirty font metrics */
                    characterSize = [character sizeWithFont:attributionStage[NSFontAttributeName]];
    #pragma clang diagnostic pop
    #endif
                }
                else {

                    characterSize = [character sizeWithAttributes:@{NSFontAttributeName: attributionStage[NSFontAttributeName]}];
                }

                attributionStage[NSKernAttributeName] = [NSNumber numberWithFloat:(-kernFactor * characterSize.width)];

                [attributedText setAttributes:attributionStage
                                        range:range];

            }

            else

            {

                //out of range

            }
//nsstring+morphing line 44
NSInteger e = endLocation - startLocation;

                    if (startLocation + e < string.length) {
                        NSRange  r = NSMakeRange(startLocation, e);

                        [mergeString appendString:[string substringWithRange:r]];
                    }
                    else
                    {
                        //out of range
                    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions