fix(bar): 修复 bar_cell_t text 字段可能为野指针 bug
This commit is contained in:
@@ -33,6 +33,11 @@ static void bar_item_cleanup(zdwm_bar_item_t *item) {
|
|||||||
if (destroy_state) destroy_state(item->state);
|
if (destroy_state) destroy_state(item->state);
|
||||||
item->state = nullptr;
|
item->state = nullptr;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < item->count; ++i) {
|
||||||
|
auto cell = &item->cells[i];
|
||||||
|
p_delete(&cell->text);
|
||||||
|
}
|
||||||
|
|
||||||
p_delete(&item->cells);
|
p_delete(&item->cells);
|
||||||
p_clear(item, 1);
|
p_clear(item, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,9 +68,11 @@ void bar_cell_set_text(zdwm_bar_item_t *item, size_t index, const char *text) {
|
|||||||
if (index >= item->count) return;
|
if (index >= item->count) return;
|
||||||
|
|
||||||
auto cell = &item->cells[index];
|
auto cell = &item->cells[index];
|
||||||
if (cell->text == text || strcmp(cell->text, text) == 0) return;
|
if (cell->text && text && strcmp(cell->text, text) == 0) return;
|
||||||
|
|
||||||
cell->text = text;
|
p_delete(&cell->text);
|
||||||
|
|
||||||
|
cell->text = p_strdup_nullable(text);
|
||||||
|
|
||||||
cell->dirty = true;
|
cell->dirty = true;
|
||||||
item->dirty = true;
|
item->dirty = true;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ typedef struct bar_x_region_t {
|
|||||||
|
|
||||||
typedef struct bar_cell_t {
|
typedef struct bar_cell_t {
|
||||||
zdwm_icon_t icon;
|
zdwm_icon_t icon;
|
||||||
const char *text;
|
char *text; /* 持有内存,避免野指针问题 */
|
||||||
const color_t *fg;
|
const color_t *fg;
|
||||||
const color_t *bg;
|
const color_t *bg;
|
||||||
bar_x_region_t region;
|
bar_x_region_t region;
|
||||||
|
|||||||
Reference in New Issue
Block a user