Do not count longer than necessary
And also use g_strndup. This makes allocation easier and also ensures a null-byte at the end of the string.
This commit is contained in:
parent
2ef74c0d64
commit
da846d8442
@ -421,11 +421,8 @@ static void notification_format_message(struct notification *n)
|
|||||||
n->msg = g_strchomp(n->msg);
|
n->msg = g_strchomp(n->msg);
|
||||||
|
|
||||||
/* truncate overlong messages */
|
/* truncate overlong messages */
|
||||||
if (strlen(n->msg) > DUNST_NOTIF_MAX_CHARS) {
|
if (strnlen(n->msg, DUNST_NOTIF_MAX_CHARS + 1) > DUNST_NOTIF_MAX_CHARS) {
|
||||||
char *buffer = g_malloc(DUNST_NOTIF_MAX_CHARS);
|
char * buffer = g_strndup(n->msg, DUNST_NOTIF_MAX_CHARS);
|
||||||
strncpy(buffer, n->msg, DUNST_NOTIF_MAX_CHARS);
|
|
||||||
buffer[DUNST_NOTIF_MAX_CHARS-1] = '\0';
|
|
||||||
|
|
||||||
g_free(n->msg);
|
g_free(n->msg);
|
||||||
n->msg = buffer;
|
n->msg = buffer;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user