Skip to content

Commit

Permalink
[Textbox] Small signedness fixes for password mask code.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveDavenport committed Feb 8, 2025
1 parent 1c144cc commit f43d578
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/widgets/textbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct {

PangoEllipsizeMode emode;

char *password_mask_char;
const char *password_mask_char;

const char *theme_name;
} textbox;
Expand Down
6 changes: 3 additions & 3 deletions source/widgets/textbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static void __textbox_update_pango_text(textbox *tb) {
if ((tb->flags & TB_PASSWORD) == TB_PASSWORD) {
size_t text_len = g_utf8_strlen(tb->text, -1);
size_t mask_len = strlen(tb->password_mask_char);
unsigned char string[text_len * mask_len + 1];
char string[text_len * mask_len + 1];
for (size_t offset = 0; offset < text_len * mask_len; offset += mask_len) {
memcpy(string + offset, tb->password_mask_char, mask_len);
}
Expand Down Expand Up @@ -554,11 +554,11 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
// We want to place the cursor based on the text shown.
const char *text = pango_layout_get_text(tb->layout);
// Clamp the position, should not be needed, but we are paranoid.
int cursor_offset;
size_t cursor_offset;

if ((tb->flags & TB_PASSWORD) == TB_PASSWORD) {
// Calculate cursor position based on mask length
int mask_len = strlen(tb->password_mask_char);
size_t mask_len = strlen(tb->password_mask_char);
cursor_offset = MIN(tb->cursor * mask_len, strlen(text));
} else {
cursor_offset = MIN(tb->cursor, g_utf8_strlen(text, -1));
Expand Down

0 comments on commit f43d578

Please sign in to comment.