Date: Wed, 15 Jul 2015 18:49:16 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285610 - head/usr.bin/calendar Message-ID: <201507151849.t6FInGBg011895@svnmir.geo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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@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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507151849.t6FInGBg011895>