Description: Fix segmentation fault when printing compound words
 get_compound() stored the address of its stack-local mrph_t into
 data->mrph; after the function returned, data.mrph was a dangling
 pointer. print_mrph() dereferenced it in the compound-word branch,
 causing random headword_len values and a crash. Pass in a mrph_t
 owned by the caller instead so the storage outlives the loop.
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Origin: other
Forwarded: not-needed
Last-Update: 2026-08-31

--- chasen-2.4.5.orig/lib/print.c
+++ chasen-2.4.5/lib/print.c
@@ -995,22 +995,21 @@ print_eos(cha_lat_t *lat, int opt_form)
 }
 
 static int
-get_compound(mrph_data_t *data, char *headword, darts_t *da, long index)
+get_compound(mrph_data_t *data, mrph_t *mrph, char *headword, darts_t *da, long index)
 {
-    mrph_t mrph;
     int has_next, hw_len;
     char *base = da_get_lex_base(da) + index;
 
     hw_len = ((short *)base)[0];
     has_next = ((short *)base)[1];
     base += sizeof(short) * 2;
-    memcpy(&mrph, base, sizeof(da_lex_t));
-    mrph.headword = headword;
-    mrph.headword_len = hw_len;
-    mrph.is_undef = 0;
-    mrph.darts = da;
+    memcpy(mrph, base, sizeof(da_lex_t));
+    mrph->headword = headword;
+    mrph->headword_len = hw_len;
+    mrph->is_undef = 0;
+    mrph->darts = da;
 
-    get_mrph_data(&mrph, data);
+    get_mrph_data(mrph, data);
 
     return has_next;
 }
@@ -1028,12 +1027,14 @@ print_mrph(cha_lat_t *lat, int path_num,
         cha_printf_mrph(lat, path_num, mdata, format); 
     } else {
 	mrph_data_t data;
+	mrph_t compound_mrph;
 	long index = mdata->compound;
 	int has_next = 1;
 	char *headword = mrph->headword;
 
 	while (has_next) {
-	    has_next = get_compound(&data, headword, mrph->darts, index);
+	    has_next = get_compound(&data, &compound_mrph,
+				    headword, mrph->darts, index);
 	    if (!has_next) {
 		if (mrph->inf_type > 0 && mdata->stem_len >= 0) {
 		    data.mrph->inf_form = mrph->inf_form;
