CoreTextHyperlinkView icon indicating copy to clipboard operation
CoreTextHyperlinkView copied to clipboard

Crash in [JSCoreTextView drawInContext:bounds:]

Open radhap opened this issue 10 years ago • 0 comments

Crash at https://github.com/jasarien/CoreTextHyperlinkView/blob/master/Classes/JSCoreTextView.m#L653 I think this line of code const CGPoint *positions = CTRunGetPositionsPtr(run); is returning NULL, and so is the crash..

Please let me know if this fix looks ok.

  •                CGPoint *positionsBuffer;
    
  •                BOOL shouldFreePositions = NO;
    
  •                if (positions == NULL) // Ptr gave NULL, we'll need to copy positions array and later free it
    
  •                {
    
  •                    CFIndex glyphCount = CTRunGetGlyphCount(run);
    
  •                    size_t positionsBufferSize = sizeof(CGPoint) \* glyphCount;
    
  •                    positionsBuffer = malloc(positionsBufferSize);
    
  •                    shouldFreePositions = YES;
    
  •                    CTRunGetPositions(run, CFRangeMake(0, 0), positionsBuffer);
    
  •                    positions = positionsBuffer;
    
  •                }
    

And later free it as

  •                if (shouldFreePositions)
    
  •                {
    
  •                    free(positionsBuffer);
    
  •                }
    

radhap avatar Aug 19 '15 14:08 radhap