diff options
| author | Eli Zaretskii | 2020-03-05 17:57:21 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2020-03-05 17:57:21 +0200 |
| commit | 88c6db91961945e4ede53d66216c2484f0c5342b (patch) | |
| tree | be4a6e02f04a7ae0d502c92f4b6912399424a0b3 /src | |
| parent | 1814c7e158685045278f991de5eba4e40e8c8199 (diff) | |
| download | emacs-88c6db91961945e4ede53d66216c2484f0c5342b.tar.gz emacs-88c6db91961945e4ede53d66216c2484f0c5342b.zip | |
Avoid crashes when a fontset has strange entries
* src/fontset.c (reorder_font_vector): Skip nil entries in the
loop that assigns scores to rfont_def's.
(fontset_compare_rfontdef): Cope with nil. This has the effect of
moving any nil entries to the end of the font-group, and avoids
crashing if an element other than the last in the font-group is
nil. (Bug#39892)
Diffstat (limited to 'src')
| -rw-r--r-- | src/fontset.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/fontset.c b/src/fontset.c index bca9452418e..c2bb8b21f26 100644 --- a/src/fontset.c +++ b/src/fontset.c | |||
| @@ -367,8 +367,14 @@ fontset_add (Lisp_Object fontset, Lisp_Object range, Lisp_Object elt, Lisp_Objec | |||
| 367 | static int | 367 | static int |
| 368 | fontset_compare_rfontdef (const void *val1, const void *val2) | 368 | fontset_compare_rfontdef (const void *val1, const void *val2) |
| 369 | { | 369 | { |
| 370 | return (RFONT_DEF_SCORE (*(Lisp_Object *) val1) | 370 | Lisp_Object v1 = *(Lisp_Object *) val1, v2 = *(Lisp_Object *) val2; |
| 371 | - RFONT_DEF_SCORE (*(Lisp_Object *) val2)); | 371 | if (NILP (v1) && NILP (v2)) |
| 372 | return 0; | ||
| 373 | else if (NILP (v1)) | ||
| 374 | return INT_MIN; | ||
| 375 | else if (NILP (v2)) | ||
| 376 | return INT_MAX; | ||
| 377 | return (RFONT_DEF_SCORE (v1) - RFONT_DEF_SCORE (v2)); | ||
| 372 | } | 378 | } |
| 373 | 379 | ||
| 374 | /* Update a cons cell which has this form: | 380 | /* Update a cons cell which has this form: |
| @@ -400,6 +406,8 @@ reorder_font_vector (Lisp_Object font_group, struct font *font) | |||
| 400 | for (i = 0; i < size; i++) | 406 | for (i = 0; i < size; i++) |
| 401 | { | 407 | { |
| 402 | Lisp_Object rfont_def = AREF (vec, i); | 408 | Lisp_Object rfont_def = AREF (vec, i); |
| 409 | if (NILP (rfont_def)) | ||
| 410 | continue; | ||
| 403 | Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def); | 411 | Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def); |
| 404 | Lisp_Object font_spec = FONT_DEF_SPEC (font_def); | 412 | Lisp_Object font_spec = FONT_DEF_SPEC (font_def); |
| 405 | int score = RFONT_DEF_SCORE (rfont_def) & 0xFF; | 413 | int score = RFONT_DEF_SCORE (rfont_def) & 0xFF; |