mirror of https://github.com/fairyglade/ly.git
Properly check the length of UTF-8 strings.(closes fairyglade#527)
This commit is contained in:
parent
4ee2b3ecc7
commit
d6d90c82c1
19
src/draw.c
19
src/draw.c
|
|
@ -10,6 +10,7 @@
|
|||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -373,10 +374,16 @@ void draw_labels(struct term_buf* buf) // throws
|
|||
}
|
||||
}
|
||||
|
||||
size_t utf8_strlen(char* s) {
|
||||
size_t len = 0;
|
||||
while (*s) len += (*s++ & 0xc0) != 0x80;
|
||||
return len;
|
||||
}
|
||||
|
||||
void draw_key_hints()
|
||||
{
|
||||
struct tb_cell* shutdown_key = str_cell(config.shutdown_key);
|
||||
int len = strlen(config.shutdown_key);
|
||||
uint16_t len = utf8_strlen(config.shutdown_key);
|
||||
if (dgn_catch())
|
||||
{
|
||||
dgn_reset();
|
||||
|
|
@ -395,31 +402,31 @@ void draw_key_hints()
|
|||
}
|
||||
else
|
||||
{
|
||||
tb_blit(len, 0, strlen(lang.shutdown), 1, shutdown);
|
||||
tb_blit(len, 0, utf8_strlen(lang.shutdown), 1, shutdown);
|
||||
free(shutdown);
|
||||
}
|
||||
|
||||
struct tb_cell* restart_key = str_cell(config.restart_key);
|
||||
len += strlen(lang.shutdown) + 1;
|
||||
len += utf8_strlen(lang.shutdown) + 1;
|
||||
if (dgn_catch())
|
||||
{
|
||||
dgn_reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
tb_blit(len, 0, strlen(config.restart_key), 1, restart_key);
|
||||
tb_blit(len, 0, utf8_strlen(config.restart_key), 1, restart_key);
|
||||
free(restart_key);
|
||||
}
|
||||
|
||||
struct tb_cell* restart = str_cell(lang.restart);
|
||||
len += strlen(config.restart_key) + 1;
|
||||
len += utf8_strlen(config.restart_key) + 1;
|
||||
if (dgn_catch())
|
||||
{
|
||||
dgn_reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
tb_blit(len, 0, strlen(lang.restart), 1, restart);
|
||||
tb_blit(len, 0, utf8_strlen(lang.restart), 1, restart);
|
||||
free(restart);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "inputs.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct box
|
||||
|
|
@ -89,4 +90,6 @@ bool cascade(struct term_buf* buf, uint8_t* fails);
|
|||
void draw_bigclock(struct term_buf *buf);
|
||||
void draw_clock(struct term_buf *buf);
|
||||
|
||||
size_t utf8_strlen(char* s);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue