diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-10-03 18:48:15 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-10-04 09:35:54 +0100 |
commit | 5bed8317ea0dc615b02f34bde9b5dfa7374c5600 (patch) | |
tree | 653b09a084652883e5256bf4b51b8949319fc392 /gobject | |
parent | 29a71915d87aa3053ed60efbe30bd7cc63ae2114 (diff) |
Warn when classes/instances exceed the allowed size, if possible
It's impossible to check this if the library user is using
g_type_register_static, but in that case their compiler should hopefully
warn about the truncation. This fixes it for G_DEFINE_TYPE and friends,
at least.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=659916
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Colin Walters <walters@verbum.org>
Diffstat (limited to 'gobject')
-rw-r--r-- | gobject/gtype.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gobject/gtype.c b/gobject/gtype.c index a96620089..a362fd502 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -2667,6 +2667,12 @@ g_type_register_static_simple (GType parent_type, { GTypeInfo info; + /* Instances are not allowed to be larger than this. If you have a big + * fixed-length array or something, point to it instead. + */ + g_return_val_if_fail (class_size <= G_MAXUINT16, G_TYPE_INVALID); + g_return_val_if_fail (instance_size <= G_MAXUINT16, G_TYPE_INVALID); + info.class_size = class_size; info.base_init = NULL; info.base_finalize = NULL; |