mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-05 15:28:42 +02:00
fix: possible memory issues
This commit is contained in:
parent
5a6471dd00
commit
a316afecb2
3
src/ui.c
3
src/ui.c
@ -109,6 +109,7 @@ static char* fmt_time(const char* fmt) {
|
||||
}
|
||||
|
||||
char* trunc_gethostname(const size_t MAXSIZE, const char* const ELLIPSIS) {
|
||||
if(utf8len(ELLIPSIS) > MAXSIZE) return NULL;
|
||||
size_t alloc_size = MAXSIZE + 1;
|
||||
char* buf = malloc(alloc_size);
|
||||
if (!buf) return NULL;
|
||||
@ -116,7 +117,7 @@ char* trunc_gethostname(const size_t MAXSIZE, const char* const ELLIPSIS) {
|
||||
if (gethostname(buf, alloc_size) == 0) return buf;
|
||||
if (errno == ENAMETOOLONG) {
|
||||
buf[alloc_size] = '\0';
|
||||
if (utf8len(buf) > MAXSIZE) {
|
||||
if (utf8len(buf) > MAXSIZE - utf8len(ELLIPSIS)) {
|
||||
strcpy(&buf[MAXSIZE - utf8len(ELLIPSIS)], ELLIPSIS);
|
||||
return buf;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user