]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix unlikely eassert failure in pgtk_enumerate_devices
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Jan 2025 06:15:50 +0000 (22:15 -0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 30 Jan 2025 18:07:13 +0000 (19:07 +0100)
* 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.

(cherry picked from commit 901659bb7046bef4ca10490cf47644fb2bc6d753)

src/pgtkterm.c

index 1f468300debee087f66d341be6a0ff4f8a9e2b08..dd85d622a6257b812ee28a06762de424d63ff551 100644 (file)
@@ -158,8 +158,6 @@ pgtk_enumerate_devices (struct pgtk_display_info *dpyinfo,
   struct pgtk_device_t *rec;
   GList *all_seats, *devices_on_seat, *tem, *t1;
   GdkSeat *seat;
-  char printbuf[1026]; /* Believe it or not, some device names are
-                         actually almost this long.  */
 
   block_input ();
   all_seats = gdk_display_list_seats (dpyinfo->gdpy);
@@ -187,13 +185,10 @@ pgtk_enumerate_devices (struct pgtk_display_info *dpyinfo,
          rec = xmalloc (sizeof *rec);
          rec->seat = g_object_ref (seat);
          rec->device = GDK_DEVICE (t1->data);
-
-         int len = snprintf (printbuf, sizeof printbuf, "%u:%s",
-                             gdk_device_get_source (rec->device),
-                             gdk_device_get_name (rec->device));
-         eassert (len < sizeof printbuf);
-
-         rec->name = build_string (printbuf);
+         rec->name = (make_formatted_string
+                      ("%u:%s",
+                       gdk_device_get_source (rec->device),
+                       gdk_device_get_name (rec->device)));
          rec->next = dpyinfo->devices;
          dpyinfo->devices = rec;
        }