svn commit: r285610 - head/usr.bin/calendar
Baptiste Daroussin
bapt at FreeBSD.org
Wed Jul 15 18:49:16 UTC 2015
Author: bapt
Date: Wed Jul 15 18:49:15 2015
New Revision: 285610
URL: https://svnweb.freebsd.org/changeset/base/285610
Log:
Fix trimming spaces writing at index -1 if an empty string is passed
Submitted by: Gennady Proskurin <gprspb at mail.ru>
Modified:
head/usr.bin/calendar/io.c
Modified: head/usr.bin/calendar/io.c
==============================================================================
--- head/usr.bin/calendar/io.c Wed Jul 15 18:18:07 2015 (r285609)
+++ head/usr.bin/calendar/io.c Wed Jul 15 18:49:15 2015 (r285610)
@@ -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;
}
More information about the svn-src-all
mailing list