From 30057e9268641e61523712e93249fb06dff95052 Mon Sep 17 00:00:00 2001
From: James R <justsomejames2@gmail.com>
Date: Sat, 5 Sep 2020 22:03:14 -0700
Subject: [PATCH 1/2] Start netid at 1 to avoid CV_FindNetVar returning a
 regular cvar for netid 0

---
 src/command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/command.c b/src/command.c
index 0a46839f3..d3e0e4969 100644
--- a/src/command.c
+++ b/src/command.c
@@ -1262,7 +1262,7 @@ void CV_RegisterVar(consvar_t *variable)
 	// check net variables
 	if (variable->flags & CV_NETVAR)
 	{
-		variable->netid = consvar_number_of_netids++;
+		variable->netid = ++consvar_number_of_netids;
 
 		/* in case of overflow... */
 		if (variable->netid > consvar_number_of_netids)

From ca9cf25423b1da21ab74e2ee52377a68f8d51c7a Mon Sep 17 00:00:00 2001
From: James R <justsomejames2@gmail.com>
Date: Sat, 5 Sep 2020 23:23:54 -0700
Subject: [PATCH 2/2] Fix netid overflow check

---
 src/command.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/command.c b/src/command.c
index d3e0e4969..ded854e49 100644
--- a/src/command.c
+++ b/src/command.c
@@ -1262,12 +1262,12 @@ void CV_RegisterVar(consvar_t *variable)
 	// check net variables
 	if (variable->flags & CV_NETVAR)
 	{
-		variable->netid = ++consvar_number_of_netids;
-
 		/* in case of overflow... */
-		if (variable->netid > consvar_number_of_netids)
+		if (consvar_number_of_netids + 1 < consvar_number_of_netids)
 			I_Error("Way too many netvars");
 
+		variable->netid = ++consvar_number_of_netids;
+
 #ifdef OLD22DEMOCOMPAT
 		CV_RegisterOldDemoVar(variable);
 #endif