From romain@blogreen.org  Fri Jan 31 08:49:34 2014
Return-Path: <romain@blogreen.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id F02BED6F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 31 Jan 2014 08:49:34 +0000 (UTC)
Received: from marvin.blogreen.org (marvin.blogreen.org [IPv6:2001:470:1f13:b9c::2])
	by mx1.freebsd.org (Postfix) with ESMTP id A89B917EB
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 31 Jan 2014 08:49:34 +0000 (UTC)
Received: by marvin.blogreen.org (Postfix, from userid 1001)
	id B91DC103598; Fri, 31 Jan 2014 09:49:31 +0100 (CET)
Message-Id: <20140131084931.B91DC103598@marvin.blogreen.org>
Date: Fri, 31 Jan 2014 09:49:31 +0100 (CET)
From: Romain Tartiere <romain@FreeBSD.org>
Reply-To: Romain Tartiere <romain@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: calendar' preprocessor process comments
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         186294
>Category:       bin
>Synopsis:       calendar(1): calendar' preprocessor process comments
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 31 08:50:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Mon Mar  3 19:00:03 UTC 2014
>Originator:     Romain Tartiere
>Release:        FreeBSD 10.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD marvin.blogreen.org 10.0-STABLE FreeBSD 10.0-STABLE #1 r261284: Thu Jan 30 13:25:27 CET 2014 root@marvin.blogreen.org:/usr/obj/usr/src/sys/MARVIN amd64

>Description:

After updating to 10.0, calendar now shows events it did not displayed
in 9.2.

>How-To-Repeat:

My ~/.calendar/calendar appears to have a commented-out comment:

---------------------------------- 8< ----------------------------------
/*
 * #include <calendar.computer>
 */

01 Jan	Sample entry
---------------------------------- 8< ----------------------------------

When I ask events for a particular date, events from this included
calendar.computer are unexpectedly returned:

---------------------------------- 8< ----------------------------------
% calendar -t 01.01
 1 jan  Sample entry
 1 jan  The Epoch (Time 0 for UNIX systems, Midnight GMT, 1970)
 1 jan  AT&T officially divests its local Bell companies, 1984
---------------------------------- 8< ----------------------------------

>Fix:

No fix yet, but a workaround is to #define a macro checked in the
included calendar
---------------------------------- 8< ----------------------------------
/*
 * #define _calendar_computer_
 * #include <calendar.computer>
 */
---------------------------------- 8< ----------------------------------



>Release-Note:
>Audit-Trail:

From: oliver <oliver@beefrankly.org>
To: bug-followup@FreeBSD.org, romain@FreeBSD.org
Cc:  
Subject: Re: bin/186294: calendar(1): calendar&#39; preprocessor process
 comments
Date: Wed, 19 Feb 2014 18:02:47 +0100

 --MP_/ONNxqFP+Gg.1MY4tHsvQ6Bf
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 This issue is caused by the reimplementation of some cpp features in
 the application, to get rid of cpp itself. The implementation lacks
 the removal of c-style /* */ comments completely.
 
 This bug seems to be a duplicate  / same issue as PR: bin/184648
 
 Attached is a patch that removes single-line and multi-line comments
 included in the calendar files by removing them in the temporary buffer.
 
 This patch fixes this issue and bin/184648.
 
 Feel free to give me some feedback about the code (style) itself, the
 report followup itself, etc..
 --MP_/ONNxqFP+Gg.1MY4tHsvQ6Bf
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=patch.txt
 
 --- calcpp.c	2014-02-19 17:56:34.000000000 +0100
 +++ /usr/src/usr.bin/calendar/calcpp.c	2014-02-19 00:43:47.000000000 +0100
 @@ -52,8 +52,6 @@
  static void pushfp(FILE *fp);
  static FILE *popfp(void);
  static int tokenscpp(char *buf, char *string);
 -static void striptags(char *buf, int size, const char *ts, const char *te);
 -static void rmcomments(char *buf, int size); 
  
  #define T_INVALID	-1
  #define T_INCLUDE	0
 @@ -95,7 +93,6 @@
  			return(fp);
  		}
  	}
 -	rmcomments(buf,size);
  	switch (tokenscpp(buf, name)) {
  	case T_INCLUDE:
  		*buf = '\0';
 @@ -233,46 +230,3 @@
  			return (1);
  	return (0);
  }
 -
 -
 -
 -
 -
 -static void 
 -rmcomments(char *buf, int size) 
 -{
 -    	striptags(buf,size,"/*", "*/");
 -}
 -
 -
 -static void 
 -striptags(char *buf, int size, const char *ts, const char *te)
 -{
 -    	static int cf = 0; /* carry flag */
 -    	int te_len = strlen(te); /* end tag length */
 - 	char *idx_ts = strstr(buf, ts);
 -    	char *idx_te = strstr(buf, te);
 -
 -    	if (idx_ts == NULL && idx_te == NULL) {
 -        	if (cf == 0)
 -            		return;
 -        	else  
 -            		*buf='\0';
 -    	} else if (idx_ts != NULL && idx_te == NULL) {
 -            	if (cf == 0) {
 -                	cf = 1;
 -                	while (buf++ != idx_ts); 
 -            	}
 -            	*buf = '\0';
 -    	} else if (idx_ts != NULL && idx_te != NULL && cf == 0 
 -	    	&& idx_ts < idx_te) {
 -            	memmove(idx_ts, idx_te+te_len,
 -	    	       (buf+size)-(idx_ts+te_len));
 -            	striptags(buf,size,ts,te);
 -    	} else if (idx_ts == NULL && idx_te != NULL && cf == 1) {
 -            	memmove(buf, idx_te+te_len,
 -	    	       (buf+size)-(idx_te+te_len));
 -            	cf = 0;
 -    	}
 -	return;
 -}
 
 --MP_/ONNxqFP+Gg.1MY4tHsvQ6Bf
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=patch.txt
 
 --- calcpp.c	2014-02-19 17:56:34.000000000 +0100
 +++ /usr/src/usr.bin/calendar/calcpp.c	2014-02-19 00:43:47.000000000 +0100
 @@ -52,8 +52,6 @@
  static void pushfp(FILE *fp);
  static FILE *popfp(void);
  static int tokenscpp(char *buf, char *string);
 -static void striptags(char *buf, int size, const char *ts, const char *te);
 -static void rmcomments(char *buf, int size); 
  
  #define T_INVALID	-1
  #define T_INCLUDE	0
 @@ -95,7 +93,6 @@
  			return(fp);
  		}
  	}
 -	rmcomments(buf,size);
  	switch (tokenscpp(buf, name)) {
  	case T_INCLUDE:
  		*buf = '\0';
 @@ -233,46 +230,3 @@
  			return (1);
  	return (0);
  }
 -
 -
 -
 -
 -
 -static void 
 -rmcomments(char *buf, int size) 
 -{
 -    	striptags(buf,size,"/*", "*/");
 -}
 -
 -
 -static void 
 -striptags(char *buf, int size, const char *ts, const char *te)
 -{
 -    	static int cf = 0; /* carry flag */
 -    	int te_len = strlen(te); /* end tag length */
 - 	char *idx_ts = strstr(buf, ts);
 -    	char *idx_te = strstr(buf, te);
 -
 -    	if (idx_ts == NULL && idx_te == NULL) {
 -        	if (cf == 0)
 -            		return;
 -        	else  
 -            		*buf='\0';
 -    	} else if (idx_ts != NULL && idx_te == NULL) {
 -            	if (cf == 0) {
 -                	cf = 1;
 -                	while (buf++ != idx_ts); 
 -            	}
 -            	*buf = '\0';
 -    	} else if (idx_ts != NULL && idx_te != NULL && cf == 0 
 -	    	&& idx_ts < idx_te) {
 -            	memmove(idx_ts, idx_te+te_len,
 -	    	       (buf+size)-(idx_ts+te_len));
 -            	striptags(buf,size,ts,te);
 -    	} else if (idx_ts == NULL && idx_te != NULL && cf == 1) {
 -            	memmove(buf, idx_te+te_len,
 -	    	       (buf+size)-(idx_te+te_len));
 -            	cf = 0;
 -    	}
 -	return;
 -}
 
 --MP_/ONNxqFP+Gg.1MY4tHsvQ6Bf--

From: oliver <oliver@beefrankly.org>
To: bug-followup@FreeBSD.org, romain@FreeBSD.org
Cc:  
Subject: Re: bin/186294: calendar(1): calendar&#39; preprocessor process
 comments
Date: Wed, 19 Feb 2014 18:16:25 +0100

 --MP_/NAgdYqlUya1F0SfphC5qWGw
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 sorry wrong patch file, patch again - correct version.
 --MP_/NAgdYqlUya1F0SfphC5qWGw
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=patch.txt
 
 --- /usr/src/usr.bin/calendar/calcpp.c	2014-02-19 00:43:47.000000000 +0100
 +++ calcpp.c	2014-02-19 17:56:34.000000000 +0100
 @@ -52,6 +52,8 @@
  static void pushfp(FILE *fp);
  static FILE *popfp(void);
  static int tokenscpp(char *buf, char *string);
 +static void striptags(char *buf, int size, const char *ts, const char *te);
 +static void rmcomments(char *buf, int size); 
  
  #define T_INVALID	-1
  #define T_INCLUDE	0
 @@ -93,6 +95,7 @@
  			return(fp);
  		}
  	}
 +	rmcomments(buf,size);
  	switch (tokenscpp(buf, name)) {
  	case T_INCLUDE:
  		*buf = '\0';
 @@ -230,3 +233,46 @@
  			return (1);
  	return (0);
  }
 +
 +
 +
 +
 +
 +static void 
 +rmcomments(char *buf, int size) 
 +{
 +    	striptags(buf,size,"/*", "*/");
 +}
 +
 +
 +static void 
 +striptags(char *buf, int size, const char *ts, const char *te)
 +{
 +    	static int cf = 0; /* carry flag */
 +    	int te_len = strlen(te); /* end tag length */
 + 	char *idx_ts = strstr(buf, ts);
 +    	char *idx_te = strstr(buf, te);
 +
 +    	if (idx_ts == NULL && idx_te == NULL) {
 +        	if (cf == 0)
 +            		return;
 +        	else  
 +            		*buf='\0';
 +    	} else if (idx_ts != NULL && idx_te == NULL) {
 +            	if (cf == 0) {
 +                	cf = 1;
 +                	while (buf++ != idx_ts); 
 +            	}
 +            	*buf = '\0';
 +    	} else if (idx_ts != NULL && idx_te != NULL && cf == 0 
 +	    	&& idx_ts < idx_te) {
 +            	memmove(idx_ts, idx_te+te_len,
 +	    	       (buf+size)-(idx_ts+te_len));
 +            	striptags(buf,size,ts,te);
 +    	} else if (idx_ts == NULL && idx_te != NULL && cf == 1) {
 +            	memmove(buf, idx_te+te_len,
 +	    	       (buf+size)-(idx_te+te_len));
 +            	cf = 0;
 +    	}
 +	return;
 +}
 
 --MP_/NAgdYqlUya1F0SfphC5qWGw--

From: Romain =?iso-8859-1?Q?Tarti=E8re?= <romain@blogreen.org>
To: oliver <oliver@beefrankly.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/186294: calendar(1): calendar&#39; preprocessor process
 comments
Date: Wed, 19 Feb 2014 19:29:00 +0100

 --6e7ZaeXHKrTJCxdu
 Content-Type: text/plain; charset=iso-8859-1
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Hi Oliver,
 
 On Wed, Feb 19, 2014 at 06:16:25PM +0100, oliver wrote:
 > sorry wrong patch file, patch again - correct version.
 
 After applying this patch, I confirm this problem is fixed.
 
 > +    	} else if (idx_ts !=3D NULL && idx_te =3D=3D NULL) {
 > +            	if (cf =3D=3D 0) {
 > +                	cf =3D 1;
 > +                	while (buf++ !=3D idx_ts);=20
                         ^^^^^^^^^^^^^^^^^^^^^^^
 
 While copying/pasting the patch, this line confused me a bit.  Isn't it
 more obvious to write this as a simple assignment ?
 
 > buf =3D idx_ts + 1;
 
 Thanks!
 
 Romain
 
 --=20
 Romain Tarti=E8re <romain@blogreen.org>        http://romain.blogreen.org/
 pgp: 8234 9A78 E7C0 B807 0B59  80FF BA4D 1D95 5112 336F (ID: 0x5112336F)
 (plain text =3Dnon-HTML=3D PGP/GPG encrypted/signed e-mail much appreciated)
 
 --6e7ZaeXHKrTJCxdu
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (FreeBSD)
 
 iQGcBAEBAgAGBQJTBPfrAAoJELpNHZVREjNvI7kL/26Y8PN8mqeqeXpfZwDY1c7k
 vsOpqAqbM1FSSomabTsmRXriPL+xDBg+KXtnnxiHZuW1dLR0UrhQq4n39JaG2eWi
 6uuNV/QHiFt0FM+gcUtL8zIBWchQ1dnVPVYpiw0pZ1zWof8yAHMMnfGo+m+gSE0D
 D/bZqSN2qf/LD+4TQnNJ/66tcIuIgKNc0TbVyo44zYo8tWvBSOwgDkcyCg4uVI/w
 VI7a4xgGcG76uOHs4KBqPHPBCcxLM83b8Wri26Ye9xi2+P8edBVMnqmLmZn9uz/w
 qzkWyeI4ld9WmqVNIUQCGOB32h4CodvfPHC4kdAmNjH7erXG65nmaJ0fjwL9Fz6m
 svHH3lAvHawe2mQzQFehnlwRSzHvGZWwr9RMEMiCjrRZxtnHMHlUyJOUX+pIS2Oc
 OZSbCWCVRguy03riaBtLIKgFcQDKbaSjj+rZHkQ3os45Ioh96+21jkKqiWPGgxNX
 zWhFA7c7acw43wuLY+8SSuYAkhj86UX7SqcxjRTzlA==
 =Y74c
 -----END PGP SIGNATURE-----
 
 --6e7ZaeXHKrTJCxdu--

From: oliver <oliver@beefrankly.org>
To: bug-followup@FreeBSD.org, romain@FreeBSD.org
Cc:  
Subject: Re: bin/186294: calendar(1): calendar&#39; preprocessor process
 comments
Date: Wed, 19 Feb 2014 20:47:24 +0100

 Hello Romain,
 
 that is very true...when removing the original block, I didn't remove
 the while condition, even stepping through is not anymore required.
 
 Sorry, I will fix that. 
 
 For so long, please don't commit the patch. I'm digging a bit deeper
 for PR: bin/162211 and found another issue..please stand by, will
 post the corrected version shortly...but need to make other
 tests first.
 
 
 Greetings, Oliver
 
 
 
 >Hi Oliver,
 
 >On Wed, Feb 19, 2014 at 06:16:25PM +0100, oliver wrote:
 >> sorry wrong patch file, patch again - correct version.
 
 >After applying this patch, I confirm this problem is fixed.
 
 >> + } else if (idx_ts != NULL && idx_te == NULL) {
 >> + if (cf == 0) {
 >> + cf = 1;
 >> + while (buf++ != idx_ts); 
 > ^^^^^^^^^^^^^^^^^^^^^^^
 
 >While copying/pasting the patch, this line confused me a bit. Isn't it
 >more obvious to write this as a simple assignment ?
 
 >> buf = idx_ts + 1;
 
 >Thanks!
 
 >Romain

From: oliver <oliver@beefrankly.org>
To: bug-followup@FreeBSD.org, romain@FreeBSD.org
Cc:  
Subject: Re: bin/186294: calendar(1): calendar&#39; preprocessor process
 comments
Date: Mon, 3 Mar 2014 19:54:02 +0100

 --MP_/PvNvoarowC1Efp0H7PxZt==
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 okay, here is my final patch for this issue and issue bin/184648
 
 I modified my original patch for removing multiple inline comments. I
 tested it against an original version of calendar and did not find any
 additional issues.
 
 Greetings, Oliver
 --MP_/PvNvoarowC1Efp0H7PxZt==
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=patch3.txt
 
 --- /usr/src/usr.bin/calendar/calcpp.c	2014-03-03 19:22:25.000000000 +0100
 +++ calcpp.c	2014-03-03 19:19:37.000000000 +0100
 @@ -52,6 +52,8 @@
  static void pushfp(FILE *fp);
  static FILE *popfp(void);
  static int tokenscpp(char *buf, char *string);
 +static void striptags(char *buf, int size, const char *ts, const char *te);
 +static void rmcomments(char *buf, int size); 
  
  #define T_INVALID	-1
  #define T_INCLUDE	0
 @@ -93,6 +95,7 @@
  			return(fp);
  		}
  	}
 +	rmcomments(buf,size);
  	switch (tokenscpp(buf, name)) {
  	case T_INCLUDE:
  		*buf = '\0';
 @@ -230,3 +233,48 @@
  			return (1);
  	return (0);
  }
 +
 +
 +
 +
 +
 +static void 
 +rmcomments(char *buf, int size) 
 +{
 +    	striptags(buf,size,"/*", "*/");
 +}
 +
 +
 +static void 
 +striptags(char *buf, int size, const char *ts, const char *te)
 +{
 +    	static int cf = 0; /* carry flag */
 +    	int te_len = strlen(te); /* end tag length */
 + 	char *idx_ts = strstr(buf, ts);
 +    	char *idx_te = strstr(buf, te);
 +    	if (idx_ts == NULL && idx_te == NULL) {
 +        	if (cf == 0)
 +            		return;
 +        	else  
 +            		*buf='\0';
 +    	} else if (idx_ts != NULL && idx_te == NULL) {
 +            	if (cf == 0) {
 +                	cf = 1;
 +                	buf = idx_ts; 
 +            	}
 +            	*buf = '\0';
 +    	} else if (idx_ts != NULL && idx_te != NULL && cf == 0) { 
 +	    	if (idx_ts < idx_te) {
 +        		memmove(idx_ts, idx_te+te_len,
 +	       		       (buf+size)-(idx_ts+te_len));
 +		} else {
 +			buf = idx_ts;
 +		}
 +            	striptags(buf,size,ts,te);
 +    	} else if (idx_ts == NULL && idx_te != NULL && cf == 1) {
 +            	memmove(buf, idx_te+te_len,
 +	    	       (buf+size)-(idx_te+te_len));
 +            	cf = 0;
 +    	}
 +	return;
 +}
 
 --MP_/PvNvoarowC1Efp0H7PxZt==--
>Unformatted:
