diff options
Diffstat (limited to 'src/gtkutil.c')
| -rw-r--r-- | src/gtkutil.c | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index 8826b08851a..c39119c8151 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -487,7 +487,8 @@ get_utf8_string (const char *str) | |||
| 487 | if (!utf8_str) | 487 | if (!utf8_str) |
| 488 | { | 488 | { |
| 489 | /* Probably some control characters in str. Escape them. */ | 489 | /* Probably some control characters in str. Escape them. */ |
| 490 | size_t nr_bad = 0; | 490 | ptrdiff_t len; |
| 491 | ptrdiff_t nr_bad = 0; | ||
| 491 | gsize bytes_read; | 492 | gsize bytes_read; |
| 492 | gsize bytes_written; | 493 | gsize bytes_written; |
| 493 | unsigned char *p = (unsigned char *)str; | 494 | unsigned char *p = (unsigned char *)str; |
| @@ -511,7 +512,10 @@ get_utf8_string (const char *str) | |||
| 511 | } | 512 | } |
| 512 | if (cp) g_free (cp); | 513 | if (cp) g_free (cp); |
| 513 | 514 | ||
| 514 | up = utf8_str = xmalloc (strlen (str) + nr_bad * 4 + 1); | 515 | len = strlen (str); |
| 516 | if ((min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4 < nr_bad) | ||
| 517 | memory_full (SIZE_MAX); | ||
| 518 | up = utf8_str = xmalloc (len + nr_bad * 4 + 1); | ||
| 515 | p = (unsigned char *)str; | 519 | p = (unsigned char *)str; |
| 516 | 520 | ||
| 517 | while (! (cp = g_locale_to_utf8 ((char *)p, -1, &bytes_read, | 521 | while (! (cp = g_locale_to_utf8 ((char *)p, -1, &bytes_read, |
| @@ -1907,12 +1911,12 @@ xg_get_file_name (FRAME_PTR f, | |||
| 1907 | int filesel_done = 0; | 1911 | int filesel_done = 0; |
| 1908 | xg_get_file_func func; | 1912 | xg_get_file_func func; |
| 1909 | 1913 | ||
| 1910 | #if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN) | 1914 | #if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) |
| 1911 | /* I really don't know why this is needed, but without this the GLIBC add on | 1915 | /* I really don't know why this is needed, but without this the GLIBC add on |
| 1912 | library linuxthreads hangs when the Gnome file chooser backend creates | 1916 | library linuxthreads hangs when the Gnome file chooser backend creates |
| 1913 | threads. */ | 1917 | threads. */ |
| 1914 | sigblock (sigmask (__SIGRTMIN)); | 1918 | sigblock (sigmask (__SIGRTMIN)); |
| 1915 | #endif /* HAVE_GTK_AND_PTHREAD */ | 1919 | #endif /* HAVE_PTHREAD */ |
| 1916 | 1920 | ||
| 1917 | #ifdef HAVE_GTK_FILE_SELECTION_NEW | 1921 | #ifdef HAVE_GTK_FILE_SELECTION_NEW |
| 1918 | 1922 | ||
| @@ -1932,7 +1936,7 @@ xg_get_file_name (FRAME_PTR f, | |||
| 1932 | 1936 | ||
| 1933 | filesel_done = xg_dialog_run (f, w); | 1937 | filesel_done = xg_dialog_run (f, w); |
| 1934 | 1938 | ||
| 1935 | #if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN) | 1939 | #if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) |
| 1936 | sigunblock (sigmask (__SIGRTMIN)); | 1940 | sigunblock (sigmask (__SIGRTMIN)); |
| 1937 | #endif | 1941 | #endif |
| 1938 | 1942 | ||
| @@ -1960,9 +1964,9 @@ xg_get_font_name (FRAME_PTR f, const char *default_name) | |||
| 1960 | char *fontname = NULL; | 1964 | char *fontname = NULL; |
| 1961 | int done = 0; | 1965 | int done = 0; |
| 1962 | 1966 | ||
| 1963 | #if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN) | 1967 | #if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) |
| 1964 | sigblock (sigmask (__SIGRTMIN)); | 1968 | sigblock (sigmask (__SIGRTMIN)); |
| 1965 | #endif /* HAVE_GTK_AND_PTHREAD */ | 1969 | #endif /* HAVE_PTHREAD */ |
| 1966 | 1970 | ||
| 1967 | w = gtk_font_selection_dialog_new ("Pick a font"); | 1971 | w = gtk_font_selection_dialog_new ("Pick a font"); |
| 1968 | if (!default_name) | 1972 | if (!default_name) |
| @@ -1974,7 +1978,7 @@ xg_get_font_name (FRAME_PTR f, const char *default_name) | |||
| 1974 | 1978 | ||
| 1975 | done = xg_dialog_run (f, w); | 1979 | done = xg_dialog_run (f, w); |
| 1976 | 1980 | ||
| 1977 | #if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN) | 1981 | #if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) |
| 1978 | sigunblock (sigmask (__SIGRTMIN)); | 1982 | sigunblock (sigmask (__SIGRTMIN)); |
| 1979 | #endif | 1983 | #endif |
| 1980 | 1984 | ||
| @@ -3296,8 +3300,8 @@ static int scroll_bar_width_for_theme; | |||
| 3296 | static struct | 3300 | static struct |
| 3297 | { | 3301 | { |
| 3298 | GtkWidget **widgets; | 3302 | GtkWidget **widgets; |
| 3299 | int max_size; | 3303 | ptrdiff_t max_size; |
| 3300 | int used; | 3304 | ptrdiff_t used; |
| 3301 | } id_to_widget; | 3305 | } id_to_widget; |
| 3302 | 3306 | ||
| 3303 | /* Grow this much every time we need to allocate more */ | 3307 | /* Grow this much every time we need to allocate more */ |
| @@ -3306,17 +3310,20 @@ static struct | |||
| 3306 | 3310 | ||
| 3307 | /* Store the widget pointer W in id_to_widget and return the integer index. */ | 3311 | /* Store the widget pointer W in id_to_widget and return the integer index. */ |
| 3308 | 3312 | ||
| 3309 | static int | 3313 | static ptrdiff_t |
| 3310 | xg_store_widget_in_map (GtkWidget *w) | 3314 | xg_store_widget_in_map (GtkWidget *w) |
| 3311 | { | 3315 | { |
| 3312 | int i; | 3316 | ptrdiff_t i; |
| 3313 | 3317 | ||
| 3314 | if (id_to_widget.max_size == id_to_widget.used) | 3318 | if (id_to_widget.max_size == id_to_widget.used) |
| 3315 | { | 3319 | { |
| 3316 | int new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR; | 3320 | ptrdiff_t new_size; |
| 3321 | if (TYPE_MAXIMUM (Window) - ID_TO_WIDGET_INCR < id_to_widget.max_size) | ||
| 3322 | memory_full (SIZE_MAX); | ||
| 3317 | 3323 | ||
| 3318 | id_to_widget.widgets = xrealloc (id_to_widget.widgets, | 3324 | new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR; |
| 3319 | sizeof (GtkWidget *)*new_size); | 3325 | id_to_widget.widgets = xnrealloc (id_to_widget.widgets, |
| 3326 | new_size, sizeof (GtkWidget *)); | ||
| 3320 | 3327 | ||
| 3321 | for (i = id_to_widget.max_size; i < new_size; ++i) | 3328 | for (i = id_to_widget.max_size; i < new_size; ++i) |
| 3322 | id_to_widget.widgets[i] = 0; | 3329 | id_to_widget.widgets[i] = 0; |
| @@ -3345,7 +3352,7 @@ xg_store_widget_in_map (GtkWidget *w) | |||
| 3345 | Called when scroll bar is destroyed. */ | 3352 | Called when scroll bar is destroyed. */ |
| 3346 | 3353 | ||
| 3347 | static void | 3354 | static void |
| 3348 | xg_remove_widget_from_map (int idx) | 3355 | xg_remove_widget_from_map (ptrdiff_t idx) |
| 3349 | { | 3356 | { |
| 3350 | if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) | 3357 | if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) |
| 3351 | { | 3358 | { |
| @@ -3357,7 +3364,7 @@ xg_remove_widget_from_map (int idx) | |||
| 3357 | /* Get the widget pointer at IDX from id_to_widget. */ | 3364 | /* Get the widget pointer at IDX from id_to_widget. */ |
| 3358 | 3365 | ||
| 3359 | static GtkWidget * | 3366 | static GtkWidget * |
| 3360 | xg_get_widget_from_map (int idx) | 3367 | xg_get_widget_from_map (ptrdiff_t idx) |
| 3361 | { | 3368 | { |
| 3362 | if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) | 3369 | if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) |
| 3363 | return id_to_widget.widgets[idx]; | 3370 | return id_to_widget.widgets[idx]; |
| @@ -3396,10 +3403,10 @@ xg_get_default_scrollbar_width (void) | |||
| 3396 | /* Return the scrollbar id for X Window WID on display DPY. | 3403 | /* Return the scrollbar id for X Window WID on display DPY. |
| 3397 | Return -1 if WID not in id_to_widget. */ | 3404 | Return -1 if WID not in id_to_widget. */ |
| 3398 | 3405 | ||
| 3399 | int | 3406 | ptrdiff_t |
| 3400 | xg_get_scroll_id_for_window (Display *dpy, Window wid) | 3407 | xg_get_scroll_id_for_window (Display *dpy, Window wid) |
| 3401 | { | 3408 | { |
| 3402 | int idx; | 3409 | ptrdiff_t idx; |
| 3403 | GtkWidget *w; | 3410 | GtkWidget *w; |
| 3404 | 3411 | ||
| 3405 | w = xg_win_to_widget (dpy, wid); | 3412 | w = xg_win_to_widget (dpy, wid); |
| @@ -3421,7 +3428,7 @@ xg_get_scroll_id_for_window (Display *dpy, Window wid) | |||
| 3421 | static void | 3428 | static void |
| 3422 | xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data) | 3429 | xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data) |
| 3423 | { | 3430 | { |
| 3424 | int id = (intptr_t) data; | 3431 | intptr_t id = (intptr_t) data; |
| 3425 | xg_remove_widget_from_map (id); | 3432 | xg_remove_widget_from_map (id); |
| 3426 | } | 3433 | } |
| 3427 | 3434 | ||
| @@ -3496,7 +3503,7 @@ xg_create_scroll_bar (FRAME_PTR f, | |||
| 3496 | /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */ | 3503 | /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */ |
| 3497 | 3504 | ||
| 3498 | void | 3505 | void |
| 3499 | xg_remove_scroll_bar (FRAME_PTR f, int scrollbar_id) | 3506 | xg_remove_scroll_bar (FRAME_PTR f, ptrdiff_t scrollbar_id) |
| 3500 | { | 3507 | { |
| 3501 | GtkWidget *w = xg_get_widget_from_map (scrollbar_id); | 3508 | GtkWidget *w = xg_get_widget_from_map (scrollbar_id); |
| 3502 | if (w) | 3509 | if (w) |
| @@ -3515,7 +3522,7 @@ xg_remove_scroll_bar (FRAME_PTR f, int scrollbar_id) | |||
| 3515 | 3522 | ||
| 3516 | void | 3523 | void |
| 3517 | xg_update_scrollbar_pos (FRAME_PTR f, | 3524 | xg_update_scrollbar_pos (FRAME_PTR f, |
| 3518 | int scrollbar_id, | 3525 | ptrdiff_t scrollbar_id, |
| 3519 | int top, | 3526 | int top, |
| 3520 | int left, | 3527 | int left, |
| 3521 | int width, | 3528 | int width, |
| @@ -4429,7 +4436,7 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 4429 | int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); | 4436 | int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); |
| 4430 | int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | 4437 | int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); |
| 4431 | int idx; | 4438 | int idx; |
| 4432 | int img_id; | 4439 | ptrdiff_t img_id; |
| 4433 | int icon_size = 0; | 4440 | int icon_size = 0; |
| 4434 | struct image *img = NULL; | 4441 | struct image *img = NULL; |
| 4435 | Lisp_Object image; | 4442 | Lisp_Object image; |