diff --git a/desktop.c b/desktop.c index 28c7a47..81f5ec9 100644 --- a/desktop.c +++ b/desktop.c @@ -26,6 +26,31 @@ static char name_llcc[64] = { 0 }; static char generic_name_ll[64] = { 0 }; static char generic_name_llcc[64] = { 0 }; + /* + * this snippet stolen from Fabrice Bellard + * as used in qemu + * https://github.com/qemu/qemu/blob/master/util/cutils.c + * as an attempt to replace strncpy + */ + +void +pstrcpy(char *buf, int buf_size, const char *str) +{ + int c; + char *q = buf; + + if (buf_size <= 0) + return; + + for(;;) { + c = *str++; + if (c == 0 || q >= buf + buf_size - 1) + break; + *q++ = c; + } + *q = '\0'; +} + static void i18n_init(void) { @@ -48,14 +73,14 @@ i18n_init(void) } /* ll_CC */ - strncpy(llcc, p, sizeof(llcc)); + pstrcpy(llcc, sizeof(llcc), p); p = strrchr(llcc, '.'); if (p) { *p = '\0'; } /* ll */ - strncpy(ll, llcc, sizeof(ll)); + pstrcpy(ll, sizeof(ll), llcc); p = strrchr(ll, '_'); if (p) { *p = '\0'; diff --git a/desktop.h b/desktop.h index 5f7720f..6fad5c2 100644 --- a/desktop.h +++ b/desktop.h @@ -21,6 +21,7 @@ struct app { bool has_been_mapped; }; +void pstrcpy(char *buf, int buf_size, const char *str); /* desktop_entries_create - parse system .desktop files */ GList *desktop_entries_create(void); void desktop_entries_destroy(GList *apps);