diff options
author | bapt <bapt@FreeBSD.org> | 2015-07-15 18:49:15 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-07-15 18:49:15 +0000 |
commit | f5525a768b5e28c474ef73325929a8f9595679c4 (patch) | |
tree | 55011cad05835a0c781be4b4dc6adf0930d565d1 | |
parent | 55f3e632fbf869c19c0fdd437056f9120201941a (diff) | |
download | FreeBSD-src-f5525a768b5e28c474ef73325929a8f9595679c4.zip FreeBSD-src-f5525a768b5e28c474ef73325929a8f9595679c4.tar.gz |
Fix trimming spaces writing at index -1 if an empty string is passed
Submitted by: Gennady Proskurin <gprspb@mail.ru>
-rw-r--r-- | usr.bin/calendar/io.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index 5e5c146..89863f4 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -87,11 +87,16 @@ static void trimlr(char **buf) { char *walk = *buf; + char *last; while (isspace(*walk)) walk++; - while (isspace(walk[strlen(walk) -1])) - walk[strlen(walk) -1] = '\0'; + if (*walk != '\0') { + last = walk + strlen(walk) - 1; + while (last > walk && isspace(*last)) + last--; + *(last+1) = 0; + } *buf = walk; } |