diff options
| author | Paul Eggert | 2025-01-26 22:15:50 -0800 |
|---|---|---|
| committer | Paul Eggert | 2025-01-26 23:05:54 -0800 |
| commit | 901659bb7046bef4ca10490cf47644fb2bc6d753 (patch) | |
| tree | f5218a6312bad06a472528b994d47c4cca8d3984 | |
| parent | f8b8dddce90f5cbf6ca0be2e72b4e11cdcf581fe (diff) | |
| download | emacs-901659bb7046bef4ca10490cf47644fb2bc6d753.tar.gz emacs-901659bb7046bef4ca10490cf47644fb2bc6d753.zip | |
Fix unlikely eassert failure in pgtk_enumerate_devices
* src/pgtkterm.c (pgtk_enumerate_devices): Prefer
make_formatted_string to snprintf + build_string + eassert, as
it’s simpler and won’t crash Emacs if the eassert fails.
| -rw-r--r-- | src/pgtkterm.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 1f468300deb..dd85d622a62 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c | |||
| @@ -158,8 +158,6 @@ pgtk_enumerate_devices (struct pgtk_display_info *dpyinfo, | |||
| 158 | struct pgtk_device_t *rec; | 158 | struct pgtk_device_t *rec; |
| 159 | GList *all_seats, *devices_on_seat, *tem, *t1; | 159 | GList *all_seats, *devices_on_seat, *tem, *t1; |
| 160 | GdkSeat *seat; | 160 | GdkSeat *seat; |
| 161 | char printbuf[1026]; /* Believe it or not, some device names are | ||
| 162 | actually almost this long. */ | ||
| 163 | 161 | ||
| 164 | block_input (); | 162 | block_input (); |
| 165 | all_seats = gdk_display_list_seats (dpyinfo->gdpy); | 163 | all_seats = gdk_display_list_seats (dpyinfo->gdpy); |
| @@ -187,13 +185,10 @@ pgtk_enumerate_devices (struct pgtk_display_info *dpyinfo, | |||
| 187 | rec = xmalloc (sizeof *rec); | 185 | rec = xmalloc (sizeof *rec); |
| 188 | rec->seat = g_object_ref (seat); | 186 | rec->seat = g_object_ref (seat); |
| 189 | rec->device = GDK_DEVICE (t1->data); | 187 | rec->device = GDK_DEVICE (t1->data); |
| 190 | 188 | rec->name = (make_formatted_string | |
| 191 | int len = snprintf (printbuf, sizeof printbuf, "%u:%s", | 189 | ("%u:%s", |
| 192 | gdk_device_get_source (rec->device), | 190 | gdk_device_get_source (rec->device), |
| 193 | gdk_device_get_name (rec->device)); | 191 | gdk_device_get_name (rec->device))); |
| 194 | eassert (len < sizeof printbuf); | ||
| 195 | |||
| 196 | rec->name = build_string (printbuf); | ||
| 197 | rec->next = dpyinfo->devices; | 192 | rec->next = dpyinfo->devices; |
| 198 | dpyinfo->devices = rec; | 193 | dpyinfo->devices = rec; |
| 199 | } | 194 | } |