Use has_prefix() instead of strncmp() throughout

This is safer than hardcoded string lengths.
This commit is contained in:
Simon Ser 2025-01-07 13:21:56 +01:00 committed by Kenny Levinsen
parent c55dff95bc
commit 0c60d1581f
19 changed files with 44 additions and 49 deletions

View file

@ -293,11 +293,11 @@ static uint32_t render_status_block(struct render_context *ctx,
}
double offset = 0;
if (strncmp(block->align, "left", 4) == 0) {
if (has_prefix(block->align, "left")) {
offset = x_pos;
} else if (strncmp(block->align, "right", 5) == 0) {
} else if (has_prefix(block->align, "right")) {
offset = x_pos + width - text_width;
} else if (strncmp(block->align, "center", 6) == 0) {
} else if (has_prefix(block->align, "center")) {
offset = x_pos + (width - text_width) / 2;
}
double text_y = height / 2.0 - text_height / 2.0;