diff src/vim9compile.c @ 22637:4d4042683371 v8.2.1867

patch 8.2.1867: Vim9: argument to add() not checked for blob Commit: https://github.com/vim/vim/commit/80b0e5ea1132d1d7cf78c77bc14c686c836a0d25 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Oct 19 20:45:36 2020 +0200 patch 8.2.1867: Vim9: argument to add() not checked for blob Problem: Vim9: argument to add() not checked for blob. Solution: Add the BLOBAPPEND instruction.
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Oct 2020 21:00:04 +0200
parents 6589dae9696c
children 5bd53bf63836
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1521,6 +1521,28 @@ generate_LISTAPPEND(cctx_T *cctx)
 }
 
 /*
+ * Generate an ISN_BLOBAPPEND instruction.  Works like add().
+ * Argument count is already checked.
+ */
+    static int
+generate_BLOBAPPEND(cctx_T *cctx)
+{
+    garray_T	*stack = &cctx->ctx_type_stack;
+    type_T	*item_type;
+
+    // Caller already checked that blob_type is a blob.
+    item_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
+    if (need_type(item_type, &t_number, -1, cctx, FALSE, FALSE) == FAIL)
+	return FAIL;
+
+    if (generate_instr(cctx, ISN_BLOBAPPEND) == NULL)
+	return FAIL;
+
+    --stack->ga_len;	    // drop the argument
+    return OK;
+}
+
+/*
  * Generate an ISN_DCALL or ISN_UCALL instruction.
  * Return FAIL if the number of arguments is wrong.
  */
@@ -2570,13 +2592,18 @@ compile_call(
 		type_T	    *type = ((type_T **)stack->ga_data)[
 							    stack->ga_len - 2];
 
-		// TODO: also check for VAR_BLOB
 		if (type->tt_type == VAR_LIST)
 		{
 		    // inline "add(list, item)" so that the type can be checked
 		    res = generate_LISTAPPEND(cctx);
 		    idx = -1;
 		}
+		else if (type->tt_type == VAR_BLOB)
+		{
+		    // inline "add(blob, nr)" so that the type can be checked
+		    res = generate_BLOBAPPEND(cctx);
+		    idx = -1;
+		}
 	    }
 
 	    if (idx >= 0)
@@ -5421,7 +5448,7 @@ compile_assignment(char_u *arg, exarg_T 
 			generate_PUSHS(cctx, NULL);
 			break;
 		    case VAR_BLOB:
-			generate_PUSHBLOB(cctx, NULL);
+			generate_PUSHBLOB(cctx, blob_alloc());
 			break;
 		    case VAR_FUNC:
 			generate_PUSHFUNC(cctx, NULL, &t_func_void);
@@ -7675,6 +7702,7 @@ delete_instr(isn_T *isn)
 	case ISN_ANYINDEX:
 	case ISN_ANYSLICE:
 	case ISN_BCALL:
+	case ISN_BLOBAPPEND:
 	case ISN_CATCH:
 	case ISN_CHECKLEN:
 	case ISN_CHECKNR: