summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-01-24 18:14:52 -0500
committerAndrew Opalach <andrew@akon.city> 2025-01-24 18:14:52 -0500
commitf638237a6b4f3d3edf9bdd995c15df537f8d7e7c (patch)
tree44efce6d912c43f67548690256879d036e22e742 /src/util
parent2daa31c0629f2eb4af84d6f4fed8ac89813de056 (diff)
downloadcamu-f638237a6b4f3d3edf9bdd995c15df537f8d7e7c.tar.gz
camu-f638237a6b4f3d3edf9bdd995c15df537f8d7e7c.tar.bz2
camu-f638237a6b4f3d3edf9bdd995c15df537f8d7e7c.zip
Fix multiple bugs encountered during stress test
- Basic server resource cleanup Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/color_palette.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/util/color_palette.c b/src/util/color_palette.c
index 73dfc83..9cfdf32 100644
--- a/src/util/color_palette.c
+++ b/src/util/color_palette.c
@@ -40,31 +40,40 @@ bool camu_color_palette_init(str *path)
if (!nn_file_open(&file, path, NNWT_FILE_READONLY)) {
return false;
}
+
str s;
nn_file_read_as_str(&file, &s);
nn_file_close(&file);
json_error_t error;
json_t *root = json_loadb(s.data, s.length, 0, &error);
+ al_str_free(&s);
if (!root) {
- al_log_error("color_palette", "Failed to load %.*s as a json (%s).",
- al_str_fmt(path), error.text);
+ al_log_error("color_palette", "Failed to load %.*s as a json (%s).", al_str_fmt(path), error.text);
return false;
}
+
+ bool parsed = true;
+
json_t *special = json_object_get(root, "special");
if (!special) {
al_log_error("color_palette", "\"special\" field missing from the color palette.");
- return false;
+ parsed = false;
+ goto out;
}
+
json_t *colors = json_object_get(root, "colors");
if (!colors) {
al_log_error("color_palette", "\"colors\" field missing from the color palette.");
- return false;
+ parsed = false;
+ goto out;
}
+
json_t *object;
const char *color;
u32 value;
u32 index;
bool to_long_error;
+
for (u32 i = 0; i < ARRAY_SIZE(special_colors); i++) {
object = json_object_get(special, special_colors[i]);
if (!object) {
@@ -80,6 +89,7 @@ bool camu_color_palette_init(str *path)
al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]);
}
}
+
for (u32 i = 0; i < ARRAY_SIZE(normal_colors); i++) {
object = json_object_get(colors, normal_colors[i]);
if (!object) {
@@ -95,8 +105,13 @@ bool camu_color_palette_init(str *path)
al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]);
}
}
+
+out:
+ json_decref(root);
+
+ return parsed;
#else
(void)path;
+ return false;
#endif
- return true;
}