Bug 29675

Summary: lint fails on stdio.h
Product: Base System Reporter: Walter Campbell <wcampbel>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.3-STABLE   
Hardware: Any   
OS: Any   

Description Walter Campbell 2001-08-13 16:20:01 UTC
lint(1) will fail on C files that include stdio.h

Fix: 

I am not sure how to fix this.
How-To-Repeat: 
wcampbel@botbay (alis-2.2beta2.patched): lint -aacgprxhH *.c
alis.c:
stdio.h:299: syntax error
alis.c:56: warning: argument id unused in function channel_hash_func
alis.c:126: warning: pointer casts may be troublesome
alis.c:133: warning: pointer casts may be troublesome
alis.c:144: warning: pointer casts may be troublesome
alis.c:162: warning: pointer casts may be troublesome
alis.c:176: warning: pointer casts may be troublesome
alis.c:202: warning: pointer casts may be troublesome
alis.c:251: warning: declaration hides earlier one: tmp
alis.c:753: warning: statement not reached
alis.c:711: warning: argument argc unused in function main
alis.c:711: warning: argument argv unused in function main

This happens with make lint on ircd-hybrid 6.2rc1

netdb.h:127: warning: struct sockaddr never defined
dbuf.c:
stdio.h:299: syntax error

make lint will then error out with return code 1.

Sample code that can cause lint to error out:

#include <stdio.h>

int main(int argc, char *arvg[])
{
	printf("Test\n");
	return 0;
}

Giving the messages:
wcampbel@botbay (wcampbel): lint -aacgprxhH lint-test.c
lint-test.c:
stdio.h:299: syntax error
lint-test.c:3: warning: argument argc unused in function main
lint-test.c:3: warning: argument arvg unused in function main
wcampbel@botbay (wcampbel): echo $?
1
Comment 1 Salvo Bartolotta 2001-08-13 18:40:23 UTC
>>Number:         29675
>>Category:       bin
>>Synopsis:       lint fails on stdio.h
>>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:   Mon Aug 13 08:20:01 PDT 2001
>>Closed-Date:
>>Last-Modified:
>>Originator:     Walter Campbell
>>Release:        FreeBSD 4.3-STABLE i386
>>Organization:
>botbay.net
>>Environment:
>System: FreeBSD botbay.net 4.3-STABLE FreeBSD 4.3-STABLE #0: Fri Jul 27 
>11:53:35 EDT 2001 root@botbay.net:/usr/obj/usr/src/sys/KABEL i386

>Also checked with current cvsup (as of 11h03 EDT)

>>Description:

>lint(1) will fail on C files that include stdio.h




AFAIK, or rather, AFAICROTL (As Far As I Can Read On The Lists), lint(1) has 
not been [actively] mantained for quite a while. You may wish to search the 
archives for this topic.

AFAICS, instead of lint(1), gcc options are used. You maight want to take a 
look at the Warning options in gcc(1).

HTH (<gasp> yet another acronym :-)),
Salvo
Comment 2 Bruce Evans 2001-08-14 00:53:56 UTC
On Mon, 13 Aug 2001, Walter Campbell wrote:

> >Description:
>
> lint(1) will fail on C files that include stdio.h
>
> >How-To-Repeat:
>
> wcampbel@botbay (alis-2.2beta2.patched): lint -aacgprxhH *.c
> alis.c:
> stdio.h:299: syntax error
> ...
> This happens with make lint on ircd-hybrid 6.2rc1
> ...

What version of lint is in that?  I think thre is no problem here with
FreeBSD lint, but stdio.h is certainly broken for most foreign versions
of lint, compilers other than gcc, and old version of gcc.  The
hard-coded __attribute__(()) in it needs to be ifdef'ed, not quite as
in the following patch.

---
Index: stdio.h
===================================================================
RCS file: /home/ncvs/src/include/stdio.h,v
retrieving revision 1.34
diff -u -2 -r1.34 stdio.h
--- stdio.h	2001/04/22 01:56:08	1.34
+++ stdio.h	2001/05/04 02:28:31
@@ -69,7 +69,4 @@
 };

-/* hold a buncha junk that would grow the ABI */
-struct __sFILEX;
-
 /*
  * stdio state variables.
@@ -116,5 +113,5 @@
 	/* separate buffer for long sequences of ungetc() */
 	struct	__sbuf _ub;	/* ungetc buffer */
-	struct __sFILEX *_extra; /* additions to FILE to not break ABI */
+	struct	__sFILEX *_extra; /* additions to FILE to not break ABI */
 	int	_ur;		/* saved _r when _r is counting ungetc data */

@@ -263,7 +260,4 @@
 FILE	*fdopen __P((int, const char *));
 int	 fileno __P((FILE *));
-int	 ftrylockfile __P((FILE *));
-void	 flockfile __P((FILE *));
-void	 funlockfile __P((FILE *));
 __END_DECLS
 #endif /* not ANSI */
@@ -300,10 +294,16 @@
 int	 asprintf __P((char **, const char *, ...)) __printflike(2, 3);
 char	*ctermid_r __P((char *));
-__const char *fmtcheck __P((const char *, const char *))
-	__attribute__((__format_arg__(2)));
 char	*fgetln __P((FILE *, size_t *));
+void	 flockfile __P((FILE *));
+__const char *fmtcheck __P((const char *, const char *))
+#ifdef __GNUC__
+	__attribute__((__format_arg__(2)))
+#endif
+	    ;
 int	 fpurge __P((FILE *));
 int	 fseeko __P((FILE *, _BSD_OFF_T_, int));
 _BSD_OFF_T_ ftello __P((FILE *));
+int	 ftrylockfile __P((FILE *));
+void	 funlockfile __P((FILE *));
 int	 getw __P((FILE *));
 int	 pclose __P((FILE *));
@@ -349,7 +349,7 @@
 __BEGIN_DECLS
 int	__srget __P((FILE *));
-int	__vfscanf __P((FILE *, const char *, _BSD_VA_LIST_));
 int	__svfscanf __P((FILE *, const char *, _BSD_VA_LIST_));
 int	__swbuf __P((int, FILE *));
+int	__vfscanf __P((FILE *, const char *, _BSD_VA_LIST_));
 __END_DECLS

---

Don't use the other parts of this patch.

A more complicated ifdef like the ones in <sys/cdef.h> is required to
support old versions of gcc.

Bruce
Comment 3 Walter Campbell 2001-08-14 01:15:32 UTC
On Tue, 14 Aug 2001, Bruce Evans wrote:

> On Mon, 13 Aug 2001, Walter Campbell wrote:
>
> > >Description:
> >
> > lint(1) will fail on C files that include stdio.h
> >
> > >How-To-Repeat:
> >
> > wcampbel@botbay (alis-2.2beta2.patched): lint -aacgprxhH *.c
> > alis.c:
> > stdio.h:299: syntax error
> > ...
> > This happens with make lint on ircd-hybrid 6.2rc1
> > ...
>
> What version of lint is in that?  I think thre is no problem here with
> FreeBSD lint, but stdio.h is certainly broken for most foreign versions
> of lint, compilers other than gcc, and old version of gcc.  The
> hard-coded __attribute__(()) in it needs to be ifdef'ed, not quite as
> in the following patch.

I'm using the stock FreeBSD lint.  It does give me the syntax error,
which causes all my lint's to fail.

In response to an earlier reply, lint does things that gcc's -W flags
do not, such as identifying unused structures, functions, and helping
identify some pieces of code that can be troublesome.
Comment 4 Bruce Evans 2001-08-14 03:41:37 UTC
On Mon, 13 Aug 2001, Walter Campbell wrote:

> On Tue, 14 Aug 2001, Bruce Evans wrote:
>
> > On Mon, 13 Aug 2001, Walter Campbell wrote:
> > > wcampbel@botbay (alis-2.2beta2.patched): lint -aacgprxhH *.c
> > > alis.c:
> > > stdio.h:299: syntax error
> > > ...
> > > This happens with make lint on ircd-hybrid 6.2rc1
> > > ...
> >
> > What version of lint is in that?  I think thre is no problem here with
> > FreeBSD lint, but stdio.h is certainly broken for most foreign versions
> > of lint, compilers other than gcc, and old version of gcc.  The
> > hard-coded __attribute__(()) in it needs to be ifdef'ed, not quite as
> > in the following patch.
>
> I'm using the stock FreeBSD lint.  It does give me the syntax error,
> which causes all my lint's to fail.

I see.  I tested under -current and FreeBSD lint doesn't give the
syntax error there.  This is a bug in -current.  FreeBSD lint now uses
"/usr/bin/cc -E x c -D__attribute__(x)= ..." for the preprocessor
instead of the correct /usr/bin/cpp (in it 4.3 uses /usr/libexec/cpp
which is correct there).  Using cc instead of cpp results in __GNUC__
and possibly other wrong things being defined.  This would break all
programs that carefully use "#ifdef __GNUC ...", except some of the
breakage is worked around by defining away __attribute__(x).  But
defining away __attribute__(x) mainly breaks lint's detection of use
of this unportable feature.

Bruce
Comment 5 Juli Mallett freebsd_committer freebsd_triage 2002-05-12 04:40:23 UTC
State Changed
From-To: open->closed

Close at request of the committer: 
"the new lint import fixed it"