From d643d73c4b0b8c95341d0ccb0a8d33712d78a00d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Fri, 19 Jul 2019 12:31:49 +0200
Subject: [PATCH] encode_value: Fixed encoding bug for some variant functions.

A stray number was added to the identifier reference table.
This caused the decoder to become confused.

Fixes dumping errors for Web.SocketIO.
---
 src/encode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/encode.c b/src/encode.c
index 508fa3cd9f..dc62d23245 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -1560,7 +1560,9 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc
 		    }
 		    if (other >= id) {
 		      /* variant before termination function. */
-		      break;
+		      EDB(3, fprintf(stderr, "%*sVariant before termination function.\n",
+				     data->depth, ""));
+		      goto next_identifier_ref;
 		    }
 		    if ((other->identifier_flags & IDENTIFIER_TYPE_MASK) ==
 			IDENTIFIER_PIKE_FUNCTION) {
@@ -1582,6 +1584,8 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc
 			gs_flags = r->id_flags & ref->id_flags;
 			id = other;
 			ref = r;
+			EDB(3, fprintf(stderr, "%*sEncoding termination function.\n",
+				       data->depth, ""));
 			goto encode_pike_function;
 		      }
 		    }
-- 
GitLab