annotate src/gui_gtk_f.h @ 33815:08f9e1eac4cf v9.0.2123

patch 9.0.2123: Problem with initializing the length of range() lists Commit: https://github.com/vim/vim/commit/df63da98d8dc284b1c76cfe1b17fa0acbd6094d8 Author: Christian Brabandt <cb@256bit.org> Date: Thu Nov 23 20:14:28 2023 +0100 patch 9.0.2123: Problem with initializing the length of range() lists Problem: Problem with initializing the length of range() lists Solution: Set length explicitly when it shouldn't contain any items range() may cause a wrong calculation of list length, which may later then cause a segfault in list_find(). This is usually not a problem, because range_list_materialize() calculates the length, when it materializes the list. In addition, in list_find() when the length of the range was wrongly initialized, it may seem to be valid, so the check for list index out-of-bounds will not be true, because it is called before the list is actually materialized. And so we may eventually try to access a null pointer, causing a segfault. So this patch does 3 things: - In f_range(), when we know that the list should be empty, explicitly set the list->lv_len value to zero. This should happen, when start is larger than end (in case the stride is positive) or end is larger than start when the stride is negative. This should fix the underlying issue properly. However, - as a safety measure, let's check that the requested index is not out of range one more time, after the list has been materialized and return NULL in case it suddenly is. - add a few more tests to verify the behaviour. fixes: #13557 closes: #13563 Co-authored-by: Tim Pope <tpope@github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 23 Nov 2023 20:30:07 +0100
parents 8623ab39b421
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 #ifndef __GTK_FORM_H__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 #define __GTK_FORM_H__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
12 #ifdef USE_GTK3
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
13 #include <gtk/gtk.h>
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
14 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include <gdk/gdk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #include <gtk/gtkcontainer.h>
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
17 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #ifdef __cplusplus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 extern "C" {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
24 #define GTK_TYPE_FORM (gui_gtk_form_get_type ())
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
25 #ifdef USE_GTK3
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
26 #define GTK_FORM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_FORM, GtkForm))
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
27 #define GTK_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_FORM, GtkFormClass))
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
28 #define GTK_IS_FORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_FORM))
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
29 #define GTK_IS_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_FORM))
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
30 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #define GTK_FORM(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_FORM, GtkForm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #define GTK_FORM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_FORM, GtkFormClass))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #define GTK_IS_FORM(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_FORM))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 #define GTK_IS_FORM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FORM))
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
35 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 typedef struct _GtkForm GtkForm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 typedef struct _GtkFormClass GtkFormClass;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 struct _GtkForm
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 GtkContainer container;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 GList *children;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 GdkWindow *bin_window;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 gint freeze_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 struct _GtkFormClass
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 GtkContainerClass parent_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
55 #ifdef USE_GTK3
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
56 GType gui_gtk_form_get_type(void);
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
57 #else
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
58 GtkType gui_gtk_form_get_type(void);
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 2275
diff changeset
59 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
61 GtkWidget *gui_gtk_form_new(void);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
63 void gui_gtk_form_put(GtkForm * form, GtkWidget * widget, gint x, gint y);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
65 void gui_gtk_form_move(GtkForm *form, GtkWidget * widget, gint x, gint y);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
67 void gui_gtk_form_move_resize(GtkForm * form, GtkWidget * widget, gint x, gint y, gint w, gint h);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 11271
diff changeset
69 // These disable and enable moving and repainting respectively. If you
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 11271
diff changeset
70 // want to update the layout's offsets but do not want it to repaint
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 11271
diff changeset
71 // itself, you should use these functions.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
22659
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
73 void gui_gtk_form_freeze(GtkForm *form);
8623ab39b421 patch 8.2.1878: GTK: error for redefining function
Bram Moolenaar <Bram@vim.org>
parents: 18753
diff changeset
74 void gui_gtk_form_thaw(GtkForm *form);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #ifdef __cplusplus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 #endif
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 11271
diff changeset
80 #endif // __GTK_FORM_H__