]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Enforce name-length >= 3 for structs using GType
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 19 Nov 2017 14:29:55 +0000 (15:29 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 9 Dec 2017 13:29:36 +0000 (14:29 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=764041

codegen/valaccodestructmodule.vala
tests/Makefile.am
tests/structs/bug764041.test [new file with mode: 0644]

index eb52d472ec6586c0503bba7eaf691e4799691979..a68ffd39c46de384d5d3ff8116e44c468533f8d4 100644 (file)
@@ -168,6 +168,12 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                push_context (new EmitContext (st));
                push_line (st.source_reference);
 
+               if (get_ccode_has_type_id (st) && get_ccode_name (st).length < 3) {
+                       st.error = true;
+                       Report.error (st.source_reference, "Name `%s' is too short for struct using GType".printf (get_ccode_name (st)));
+                       return;
+               }
+
                var old_instance_finalize_context = instance_finalize_context;
                instance_finalize_context = new EmitContext ();
 
index d27c5949c94d72cc341ed149babf417f500ab006..f85348115d0feed8abea89714425d47239fc23a3 100644 (file)
@@ -129,6 +129,7 @@ TESTS = \
        structs/bug690380.vala \
        structs/bug694140.vala \
        structs/bug749952.vala \
+       structs/bug764041.test \
        structs/bug775761.vala \
        delegates/casting.vala \
        delegates/delegates.vala \
diff --git a/tests/structs/bug764041.test b/tests/structs/bug764041.test
new file mode 100644 (file)
index 0000000..1911cda
--- /dev/null
@@ -0,0 +1,10 @@
+Invalid Code
+
+struct N {
+       public int i;
+}
+
+void main() {
+       N n = { 42 };
+       Value v = n;
+}