From 7542f4a711c41f3b87f587f29e0c3032b8ffb3ea Mon Sep 17 00:00:00 2001 From: Frederic Culot Date: Sun, 14 Feb 2010 17:29:16 +0000 Subject: Avoid a segfault when txt_max_len becomes too small. Reported by Thorsten, thanks. --- src/notify.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/notify.c b/src/notify.c index 72741ed..364b4d2 100755 --- a/src/notify.c +++ b/src/notify.c @@ -1,4 +1,4 @@ -/* $calcurse: notify.c,v 1.47 2009/08/17 10:04:39 culot Exp $ */ +/* $calcurse: notify.c,v 1.48 2010/02/14 17:29:16 culot Exp $ */ /* * Calcurse - text-based organizer @@ -268,9 +268,12 @@ notify_update_bar (void) { if (strlen (notify_app.txt) > txt_max_len) { + int shrink_len; + too_long = 1; - (void)strncpy (buf, notify_app.txt, txt_max_len - 3); - buf[txt_max_len - 3] = '\0'; + shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1; + (void)strncpy (buf, notify_app.txt, shrink_len); + buf[shrink_len] = '\0'; } time_left = notify_time_left (); if (time_left > 0) -- cgit v1.2.3