From 70e5afe5ac85b68536b239e9122511c49519a597 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 16 Nov 2009 19:52:12 +0100 Subject: [PATCH] ifblock: fix clash with specials when freeing objects Murphy hit me again: in my naive attempt to fix the clash between ifblocks and objects parsing text objects due to the double use of the 'sub' field, I overlooked this problem with reusing the 'special_data' field. So here comes the real thing (TM), donating ifblocks their own field for pointing to the jump target. --- src/conky.c | 5 +++-- src/core.c | 18 ++---------------- src/text_object.c | 4 ++-- src/text_object.h | 1 + 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/conky.c b/src/conky.c index 25da11f1..a3e54de7 100644 --- a/src/conky.c +++ b/src/conky.c @@ -801,7 +801,8 @@ void generate_text_internal(char *p, int p_max_size, */ #define DO_JUMP { \ DBGP2("jumping"); \ - obj = obj->special_data; \ + if (obj->ifblock_next) \ + obj = obj->ifblock_next; \ } #define OBJ(a) break; case OBJ_##a: @@ -1167,7 +1168,7 @@ void generate_text_internal(char *p, int p_max_size, * Do Ninja jump here: without leaving traces. * This is to prevent us from stale jumped flags. */ - obj = obj->special_data; + obj = obj->ifblock_next; continue; } OBJ(endif) { diff --git a/src/core.c b/src/core.c index 60e49a43..04475431 100644 --- a/src/core.c +++ b/src/core.c @@ -1336,7 +1336,6 @@ int extract_variable_text_internal(struct text_object *retval, const char *const void free_text_objects(struct text_object *root, int internal) { struct text_object *obj; - char type_is_if; if (!root->prev) { return; @@ -1795,21 +1794,8 @@ void free_text_objects(struct text_object *root, int internal) break; #endif /* X11 */ } - type_is_if = 0; - if(obj->type == OBJ_if_gw || obj->type == OBJ_if_empty || obj->type == OBJ_if_match || obj->type == OBJ_if_existing || obj->type == OBJ_if_mounted || obj->type == OBJ_if_running || obj->type == OBJ_if_updatenr || obj->type == OBJ_if_mixer_mute) type_is_if = 1; -#if defined(IBM) - if(obj->type == OBJ_if_smapi_bat_installed) type_is_if = 1; -#endif -#if defined(__FreeBSD__) || defined(__linux__) - if(obj->type == OBJ_if_up) type_is_if = 1; -#endif -#ifdef MPD - if(obj->type == OBJ_if_mpd_playing) type_is_if = 1; -#endif -#ifdef XMMS2 - if(obj->type == OBJ_if_xmms2_connected) type_is_if = 1; -#endif - if(obj->special_data && obj->type != OBJ_else && type_is_if == 0) free(obj->special_data); + if(obj->special_data) + free(obj->special_data); free(obj); } #undef data diff --git a/src/text_object.c b/src/text_object.c index 3b0fb424..0dd7352d 100644 --- a/src/text_object.c +++ b/src/text_object.c @@ -107,7 +107,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top, case IFBLOCK_ENDIF: if (!(*ifblock_stack_top)) CRIT_ERR(NULL, NULL, "got an endif without matching if"); - (*ifblock_stack_top)->obj->special_data = obj; + (*ifblock_stack_top)->obj->ifblock_next = obj; /* if there's some else in between, remove and free it */ if ((*ifblock_stack_top)->type == IFBLOCK_ELSE) { stackobj = *ifblock_stack_top; @@ -122,7 +122,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top, case IFBLOCK_ELSE: if (!(*ifblock_stack_top)) CRIT_ERR(NULL, NULL, "got an else without matching if"); - (*ifblock_stack_top)->obj->special_data = obj; + (*ifblock_stack_top)->obj->ifblock_next = obj; /* fall through */ case IFBLOCK_IF: stackobj = malloc(sizeof(struct ifblock_stack_obj)); diff --git a/src/text_object.h b/src/text_object.h index 90ac4eb6..2fda6788 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -472,6 +472,7 @@ enum text_object_type { struct text_object { struct text_object *next, *prev; /* doubly linked list of text objects */ struct text_object *sub; /* for objects parsing text into objects */ + struct text_object *ifblock_next; /* jump target for ifblock objects */ union { void *opaque; /* new style generic per object data */ char *s; /* some string */