Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of range crash #19

Open
alariccole opened this issue Nov 17, 2014 · 2 comments
Open

Out of range crash #19

alariccole opened this issue Nov 17, 2014 · 2 comments

Comments

@alariccole
Copy link

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
                    }
@AlexanderNorway
Copy link

Why not make a pull request with this fix?

@Austinate
Copy link

Pending since Aug 4 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants