Subject: Emacs.app font initialization segfault
From: BT Templeton <[email-masked]>
To: [email-masked]
Date: Wed, 04 Jul 2012 01:00:33 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

When built under GNUstep, Emacs.app crashes while creating the initial
frame:

--8<---------------cut here---------------start------------->8---
Program received signal SIGSEGV, Segmentation fault.
ns_charset_covers (pct=<optimized out>, set2=0x1db24d8, set1=<optimized out>) at nsfont.m:279
279                     off++;
(gdb) bt
#0  ns_charset_covers (pct=<optimized out>, set2=0x1db24d8, set1=<optimized out>) at nsfont.m:279
#1  ns_get_covering_families (script=0x1c83c38, pct=<optimized out>) at nsfont.m:470
#2  ns_findfonts (font_spec=15502181, isMatch=0 '\000') at nsfont.m:514
#3  0x00000000005f1c6c in font_list_entities (frame=21141749, spec=21133645) at font.c:2754
#4  0x00000000005f3acb in font_find_for_lface (f=0x14298f0, attrs=0x7fffffffb2e0, spec=21129941, c=-1) at font.c:3225
#5  0x00000000005f3e3d in font_load_for_lface (f=0x14298f0, attrs=0x7fffffffb2e0, spec=21129941) at font.c:3291
#6  0x00000000005f4029 in font_open_by_spec (f=0x14298f0, spec=21129941) at font.c:3354
#7  0x00000000005f4093 in font_open_by_name (f=0x14298f0, name=0x1c0e5c0 "FreeMono") at font.c:3370
#8  0x000000000044b909 in x_set_font (f=0x14298f0, arg=18808561, oldval=13346530) at frame.c:3177
#9  0x000000000044a4b3 in x_set_frame_parameters (f=0x14298f0, alist=13346530) at frame.c:2822
#10 0x000000000044d5db in x_default_parameter (f=0x14298f0, alist=19139910, prop=15528290, deflt=18808561, xprop=0x6c1333 "font", xclass=0x6c132e "Font", type=RES_TYPE_STRING) at frame.c:3880
#11 0x000000000068c1a0 in Fx_create_frame (parms=19139910) at nsfns.m:1261
#12 0x00000000005d8eef in Ffuncall (nargs=2, args=0x7fffffffb7d8) at eval.c:2819
#13 0x00000000006264a9 in exec_byte_code (bytestr=9921745, vector=9921781, maxdepth=16, args_template=13346530, nargs=0, args=0x0) at bytecode.c:784
#14 0x00000000005d9982 in funcall_lambda (fun=9921677, nargs=1, arg_vector=0x7fffffffbcd0) at eval.c:3051
#15 0x00000000005d90e3 in Ffuncall (nargs=2, args=0x7fffffffbcc8) at eval.c:2868
#16 0x00000000006264a9 in exec_byte_code (bytestr=10574537, vector=10574573, maxdepth=20, args_template=13346530, nargs=0, args=0x0) at bytecode.c:784
#17 0x00000000005d9982 in funcall_lambda (fun=10574477, nargs=1, arg_vector=0x7fffffffc1c0) at eval.c:3051
#18 0x00000000005d90e3 in Ffuncall (nargs=2, args=0x7fffffffc1b8) at eval.c:2868
#19 0x00000000006264a9 in exec_byte_code (bytestr=10569457, vector=10569493, maxdepth=24, args_template=13346530, nargs=0, args=0x0) at bytecode.c:784
#20 0x00000000005d9982 in funcall_lambda (fun=10569405, nargs=0, arg_vector=0x7fffffffc6c0) at eval.c:3051
#21 0x00000000005d90e3 in Ffuncall (nargs=1, args=0x7fffffffc6b8) at eval.c:2868
#22 0x00000000006264a9 in exec_byte_code (bytestr=9959433, vector=9959469, maxdepth=72, args_template=0, nargs=0, args=0x7fffffffcc28) at bytecode.c:784
#23 0x00000000005d966d in funcall_lambda (fun=9959381, nargs=0, arg_vector=0x7fffffffcc28) at eval.c:2985
#24 0x00000000005d90e3 in Ffuncall (nargs=1, args=0x7fffffffcc20) at eval.c:2868
#25 0x00000000006264a9 in exec_byte_code (bytestr=9956345, vector=9956381, maxdepth=32, args_template=0, nargs=0, args=0x7fffffffd070) at bytecode.c:784
#26 0x00000000005d966d in funcall_lambda (fun=9956293, nargs=0, arg_vector=0x7fffffffd070) at eval.c:2985
#27 0x00000000005d942c in apply_lambda (fun=9956293, args=13346530) at eval.c:2928
#28 0x00000000005d7942 in eval_sub (form=18604566) at eval.c:2211
#29 0x00000000005d703e in Feval (form=18604566, lexical=13346530) at eval.c:2020
#30 0x00000000005d7765 in eval_sub (form=18611638) at eval.c:2169
#31 0x0000000000607440 in readevalloop (readcharfun=15462674, stream=0xee55b0, sourcename=15618625, printflag=0, unibyte=13346530, readfun=13346530, start=13346530, end=13346530) at lread.c:1819
#32 0x0000000000605ebb in Fload (file=15511473, noerror=13346530, nomessage=13346530, nosuffix=13346530, must_suffix=13346530) at lread.c:1303
#33 0x00000000005d7801 in eval_sub (form=15451142) at eval.c:2180
#34 0x00000000005d703e in Feval (form=15451142, lexical=13346530) at eval.c:2020
#35 0x000000000052fbf9 in top_level_2 () at keyboard.c:1162
#36 0x00000000005d576b in internal_condition_case (bfun=0x52fbd2 <top_level_2>, handlers=13910114, hfun=0x52f683 <cmd_error>) at eval.c:1332
#37 0x000000000052fc44 in top_level_1 (ignore=13346530) at keyboard.c:1170
#38 0x00000000005d506e in internal_catch (tag=13905986, func=0x52fbfb <top_level_1>, arg=13346530) at eval.c:1089
#39 0x000000000052fb27 in command_loop () at keyboard.c:1125
#40 0x000000000052f129 in recursive_edit_1 () at keyboard.c:752
#41 0x000000000052f318 in Frecursive_edit () at keyboard.c:816
#42 0x000000000052d15f in main (argc=2, argv=0x7fffffffe118) at emacs.c:1693

Lisp Backtrace:
"x-create-frame" (0xffffb7e0)
"x-create-frame-with-faces" (0xffffbcd0)
"make-frame" (0xffffc1c0)
"frame-initialize" (0xffffc6c0)
"command-line" (0xffffcc28)
"normal-top-level" (0xffffd070)
"eval" (0xffffd310)
"load" (0xffffd7e0)
--8<---------------cut here---------------end--------------->8---

This is probably a GNUstep bug, but the following patch fixes the
problem.

diff --git a/src/nsfont.m b/src/nsfont.m
index 556102b..302a2d0 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -271,6 +271,9 @@ ns_charset_covers(NSCharacterSet *set1, NSCharacterSet *set2, float pct)
     const unsigned short *bytes2 = [[set2 bitmapRepresentation] bytes];
     int i, off = 0, tot = 0;
 
+    if (! (bytes1 && bytes2))
+      return NO;
+
     for (i=0; i<4096; i++, bytes1++, bytes2++)
        if (*bytes2)
          {