Subject: Re: bug#11541: Possible fix
From: Jan Djärv <[email-masked]>
To: Thomas Kappler <[email-masked]>
Cc: "[email-masked]" <[email-masked]>
Date: Thu, 8 Nov 2012 20:53:32 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello.

If it works, that is good.  I installed it in the trunk.

Thanks,

	Jan D.

6 nov 2012 kl. 12:01 skrev Thomas Kappler <[email-masked]>:

> I investigated this a bit further and have a patch that fixes the right-arrow test file for me, I can open it and the arrow displays without problems.
> 
> Note that this is my very first foray into the Emacs source as well as into Objective-C.
> 
> The problem is that ns_findfonts is being passed an empty font_spec. (Why, I have no idea.) This crashes "[fdesc matchingFontDescriptorsWithMandatoryKeys: fkeys]". The fix is to check for this case and, if there are no keys in the font_spec, simply initialize matchingDescs to an empty array.
> 
> Cheers,
> Thomas
> 
> 
> $ bzr diff
> 
> === modified file 'src/nsfont.m'
> --- src/nsfont.m    2012-10-21 18:48:11 +0000
> +++ src/nsfont.m    2012-11-06 10:55:25 +0000
> @@ -43,7 +43,7 @@
>  #import <AppKit/NSFontDescriptor.h>
>  #endif
>  
> -#define NSFONT_TRACE 0
> +#define NSFONT_TRACE 1
>  
>  extern Lisp_Object Qns;
>  extern Lisp_Object Qnormal, Qbold, Qitalic, Qcondensed, Qexpanded;
> @@ -556,10 +556,17 @@
>  
>      fdesc = ns_spec_to_descriptor (font_spec);
>      fkeys = [NSMutableSet setWithArray: [[fdesc fontAttributes] allKeys]];
> +    if (NSFONT_TRACE)
> +        NSLog(@"Got %d fkeys: %@ ", [fkeys count], fkeys);
> +    
>      if (isMatch)
>      [fkeys removeObject: NSFontFamilyAttribute];
>  
> -    matchingDescs = [fdesc matchingFontDescriptorsWithMandatoryKeys: fkeys];
> +    if ([fkeys count] > 0) {
> +    matchingDescs = [fdesc matchingFontDescriptorsWithMandatoryKeys: fkeys];
> +    } else {
> +    matchingDescs = [NSMutableArray array];
> +    }
>      if (NSFONT_TRACE)
>      NSLog(@"Got desc %@ and found %d matching fonts from it: ", fdesc,
>            [matchingDescs count]);
>