[vim/vim] [vim9class] REGRESSION: SEGV using a null_object (Issue #15338)

14 views
Skip to first unread message

errael

unread,
Jul 24, 2024, 8:00:11 PM (3 days ago) Jul 24
to vim/vim, Subscribed

Steps to reproduce

vim9script

def X()
    var x = null_object
    echom x
enddef
X()

Bisecting indicates
3164cf8

date:        Thu Mar 28 10:36:42 2024 +0100
summary:     patch 9.1.0219: Vim9: No enum support

Expected behaviour

No exception, error message like

E1324: Using an Object as a String

Not all uses of null_object have this problem

Version of Vim

9.1.611

Environment

ubuntu gtk3

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15338@github.com>

errael

unread,
Jul 24, 2024, 8:18:22 PM (2 days ago) Jul 24
to vim/vim, Subscribed

FYI, I'm in the middle of some stuff, including cleanup after trying to track this down. So not sure when I'll be able to take a look. If someone starts looking, leaving a note would help.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15338/2249102223@github.com>

Christian Brabandt

unread,
Jul 25, 2024, 4:04:13 PM (2 days ago) Jul 25
to vim/vim, Subscribed

Thanks. This one should fix it:

diff --git a/src/typval.c b/src/typval.c
index 67c819f0a..e50e96af0 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -267,11 +267,16 @@ tv_get_bool_or_number_chk(
            break;
        case VAR_OBJECT:
            {
-               class_T *cl = varp->vval.v_object->obj_class;
-               if (cl != NULL && IS_ENUM(cl))
-                   semsg(_(e_using_enum_str_as_number), cl->class_name);
+               if (varp->vval.v_object == NULL)
+                   emsg(_(e_using_object_as_string));
                else
-                   emsg(_(e_using_object_as_number));
+               {
+                   class_T *cl = varp->vval.v_object->obj_class;
+                   if (cl != NULL && IS_ENUM(cl))
+                       semsg(_(e_using_enum_str_as_number), cl->class_name);
+                   else
+                       emsg(_(e_using_object_as_number));
+               }
            }
            break;
        case VAR_VOID:
@@ -1146,11 +1151,16 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
            break;
        case VAR_OBJECT:
            {
-               class_T *cl = varp->vval.v_object->obj_class;
-               if (cl != NULL && IS_ENUM(cl))
-                   semsg(_(e_using_enum_str_as_string), cl->class_name);
-               else
+               if (varp->vval.v_object == NULL)
                    emsg(_(e_using_object_as_string));
+               else
+               {
+                   class_T *cl = varp->vval.v_object->obj_class;
+                   if (cl != NULL && IS_ENUM(cl))
+                       semsg(_(e_using_enum_str_as_string), cl->class_name);
+                   else
+                       emsg(_(e_using_object_as_string));
+               }
            }
            break;
        case VAR_JOB:

Haven't yet created a proper PR with a test case yet.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15338/2251302041@github.com>

errael

unread,
Jul 25, 2024, 9:47:32 PM (2 days ago) Jul 25
to vim/vim, Subscribed

@chrisbra I tried your fix and of course it took care of the OP case. But it didn't take care of the original problem I ran into. Tracking down the original problem, I ran into 3 (count 'em, three) SEGV cases; see below. I've got them fixed and I'm putting together a PR with these fixes and your typval.c fixes. The OP case is fixed (generated an error) with the change around line 1146. I couldn't find a test for the change around line 267, any ideas?; it looks like this case might be triggered where vim9script wants to do an automatic string to int conversion, but I'm not seeing where this happens. BTW, the error reported for the line 1146 case displays the wrong line number.

I'll open a PR with both sets of fixes and some tests. (except for that missing one).

vim9script

def Z()
    var o: any = null_object
    o.v = 4
enddef
#Z()    # SEGV

class C0
    def F()
    enddef
endclass

class C extends C0
endclass

def X()
    var o: C0 = null_object
    o.F()
enddef
#X()    # SEGV

def Y()
    var o: C0 = null_object
    var XXX = o.F
enddef
#Y()    # SEGV


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15338/2251800757@github.com>

Christian Brabandt

unread,
Jul 26, 2024, 12:42:22 PM (20 hours ago) Jul 26
to vim/vim, Subscribed

Closed #15338 as completed via be82825.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/15338/issue_event/13663598004@github.com>

Reply all
Reply to author
Forward
0 new messages