From 6e04754d66421d0eece695ddf01da1a4c6fd29e9 Mon Sep 17 00:00:00 2001
From: Chris Roberts <cpr420@gmail.com>
Date: Fri, 4 Feb 2022 20:45:13 +0000
Subject: gcc2 variable declaration fixes


diff --git a/jo.c b/jo.c
index f7c2cd9..2a98392 100644
--- a/jo.c
+++ b/jo.c
@@ -219,6 +219,8 @@ JsonNode *jo_mknumber(char *str, JsonTag type) {
 JsonNode *vnode(char *str, int flags)
 {
 	JsonTag type = flags_to_tag(flags);
+	char *endptr;
+	double num;
 
 	if (strlen(str) == 0) {
 		return (flags & FLAG_SKIPNULLS) ? (JsonNode *)NULL : jo_mknull(type);
@@ -237,8 +239,7 @@ JsonNode *vnode(char *str, int flags)
 		return jo_mkstring(str, type);
 	}
 
-	char *endptr;
-	double num = strtod(str, &endptr);
+	num = strtod(str, &endptr);
 
 	if (!*endptr && isfinite(num)) {
 		return jo_mknumber(str, type);
@@ -298,10 +299,11 @@ JsonNode *vnode(char *str, int flags)
 	}
 
 	if (*str == '{' || *str == '[') {
+		JsonNode *obj;
 		if (type == JSON_STRING) {
 			return json_mkstring(str);
 		}
-		JsonNode *obj = json_decode(str);
+		obj = json_decode(str);
 
 		if (obj == NULL) {
 			/* JSON cannot be decoded; return the string */
@@ -432,17 +434,19 @@ int member_to_object(JsonNode *object, int flags, char key_delim, char *kv)
 	char *p = strchr(kv, '=');
 	char *q = strchr(kv, '@');
 	char *r = strchr(kv, ':');
+	JsonNode *val;
 
 	if ((r && *(r+1) == '=') && !q) {
 		char *filename = p + 1;
 		char *content;
 		size_t len;
+		JsonNode *o;
 
 		if ((content = slurp_file(filename, &len, false)) == NULL) {
 			errx(1, "Error reading file %s", filename);
 		}
 
-		JsonNode *o = json_decode(content);
+		o = json_decode(content);
 		free(content);
 
 		if (o == NULL) {
@@ -459,7 +463,6 @@ int member_to_object(JsonNode *object, int flags, char key_delim, char *kv)
 		return (-1);
 	}
 
-	JsonNode *val;
 	if (p) {
 		*p = 0;
 		val = vnode(p+1, flags);
diff --git a/json.c b/json.c
index ba46d18..333c108 100644
--- a/json.c
+++ b/json.c
@@ -593,8 +593,9 @@ static void prepend_node(JsonNode *parent, JsonNode *child)
 
 static void insert_node(JsonNode *parent, JsonNode *child)
 {
+	JsonNode *this;
 	if (!child) return;
-	JsonNode *this = parent->children.head;
+	this = parent->children.head;
 
 	while (this != NULL && strcmp(this->key, child->key))
 		this = this->next;
-- 
2.30.2

