aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2019-04-20 18:52:03 +0100
committerBrian Ashworth <bosrsf04@gmail.com>2019-04-20 16:41:02 -0400
commit20762ecb3c34493a6de637d37234d738467f69a9 (patch)
tree28b92fbcf8f9a24ecd76cb61aeae059973a68e3c
parent9099adbbe6fffcd7510b31efc8e547da7fa24f65 (diff)
Validate icon_struct in read_theme_file
The read_theme_file function used to return an invalid icon_struct in some cases, for example when an empty index.theme file was read. This makes sure the struct we're returning is always valid as per the Icon Theme specification. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r--swaybar/tray/icon.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c
index 56f230e1..c7e7f6bc 100644
--- a/swaybar/tray/icon.c
+++ b/swaybar/tray/icon.c
@@ -82,6 +82,10 @@ static int cmp_group(const void *item, const void *cmp_to) {
return strcmp(item, cmp_to);
}
+static bool validate_icon_theme(struct icon_theme *theme) {
+ return theme && theme->name && theme->comment && theme->directories;
+}
+
static bool group_handler(char *old_group, char *new_group,
struct icon_theme *theme) {
if (!old_group) { // first group must be "Icon Theme"
@@ -89,7 +93,7 @@ static bool group_handler(char *old_group, char *new_group,
}
if (strcmp(old_group, "Icon Theme") == 0) {
- if (!(theme->name && theme->comment && theme->directories)) {
+ if (!validate_icon_theme(theme)) {
return true;
}
} else {
@@ -276,7 +280,7 @@ static struct icon_theme *read_theme_file(char *basedir, char *theme_name) {
free(full_line);
fclose(theme_file);
- if (!error) {
+ if (!error && validate_icon_theme(theme)) {
theme->dir = strdup(theme_name);
return theme;
} else {