Re: lint and va_copy()

Previous thread: Re: MD5 Folding in kernel RNG by Theo de Raadt on Tuesday, December 28, 2010 - 3:39 pm. (2 messages)

Next thread: Line-by-line functionality for rev(1) by Vadim Zhukov on Tuesday, December 28, 2010 - 5:45 pm. (5 messages)
From: Tim van der Molen
Date: Tuesday, December 28, 2010 - 4:59 pm

lint currently does not properly handle va_copy(): a statement like
"va_copy(ap2, ap);" causes lint to issue warnings like

test.c:14: warning: ap2 may be used before set
Lint pass2:
test.c:14: __va_copy used, but not defined

Defining the following macro would be sufficient to prevent these
warnings:

#define va_copy(dst, src)	((dst) = (src))

Because most of the /usr/src/sys/arch/*/include/stdarg.h headers contain
an "#ifdef lint" block, it seems appropriate to add the above macro to
these blocks.

Unfortunately, <stdarg.h> defines va_copy(), too:

#if __ISO_C_VISIBLE >= 1999
#define va_copy(dst, src)	__va_copy((dst), (src))
#endif

This could be solved, however, by hiding this macro from lint. For
example:

#if (defined(__GNUC__) || defined(__PCC__)) && __ISO_C_VISIBLE >= 1999
#define va_copy(dst, src)	__va_copy((dst), (src))
#endif

Perhaps this change would be sensible also because __va_copy() is an
extension to standard C.

So, to conclude, what I would like to propose is the following:
* Hide from lint the va_copy() macro in <stdarg.h>.
* Add a lint-friendly va_copy() macro to
  /usr/src/sys/arch/*/include/stdarg.h.

Any thoughts?

Regards,
Tim

From: Ted Unangst
Date: Tuesday, December 28, 2010 - 6:30 pm

Does adding a lint friendly __va_copy to arch/stdarg.h work?

From: Tim van der Molen
Date: Wednesday, December 29, 2010 - 8:53 am

It does indeed. In fact, some of the stdarg.h headers (e.g. powerpc)
take this approach. Here is a diff for the remaining headers.

Regards,
Tim

Index: sys/arch/alpha/include/stdarg.h
===================================================================
RCS file: /cvs/src/sys/arch/alpha/include/stdarg.h,v
retrieving revision 1.11
diff -u sys/arch/alpha/include/stdarg.h
--- sys/arch/alpha/include/stdarg.h	23 Oct 2008 21:25:07 -0000	1.11
+++ sys/arch/alpha/include/stdarg.h	29 Dec 2010 15:34:10 -0000
@@ -45,6 +45,7 @@
 
 #ifdef lint
 #define	va_start(ap,lastarg)	((ap) = (ap))
+#define	__va_copy(dst, src)	((dst) = (src))
 #else
 #define	va_start(ap, last) \
 	(__builtin_next_arg(last), (ap) = *(va_list *)__builtin_saveregs(), (ap).pad = 0)
Index: sys/arch/amd64/include/stdarg.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/stdarg.h,v
retrieving revision 1.6
diff -u sys/arch/amd64/include/stdarg.h
--- sys/arch/amd64/include/stdarg.h	23 Oct 2008 21:25:07 -0000	1.6
+++ sys/arch/amd64/include/stdarg.h	29 Dec 2010 15:34:10 -0000
@@ -49,6 +49,7 @@
 
 #ifdef lint
 #define	va_start(ap,lastarg)	((ap) = (ap))
+#define	__va_copy(dst, src)	((dst) = (src))
 #else
 #define	va_start(ap, last) \
 	((ap) = (va_list)&(last) + __va_size(last))
Index: sys/arch/hppa/include/stdarg.h
===================================================================
RCS file: /cvs/src/sys/arch/hppa/include/stdarg.h,v
retrieving revision 1.9
diff -u sys/arch/hppa/include/stdarg.h
--- sys/arch/hppa/include/stdarg.h	23 Oct 2008 21:25:07 -0000	1.9
+++ sys/arch/hppa/include/stdarg.h	29 Dec 2010 15:34:10 -0000
@@ -41,6 +41,7 @@
 
 #ifdef lint
 #define	va_start(ap,lastarg)	((ap) = (ap))
+#define	__va_copy(dst, src)	((dst) = (src))
 #else
 #define	va_start(ap,lastarg)	((ap) = (va_list)__builtin_saveregs())
 #endif /* lint */
Index: sys/arch/hppa64/include/stdarg.h
===================================================================
RCS file: ...
From: Philip Guenther
Date: Wednesday, December 29, 2010 - 11:26 am

On Wed, Dec 29, 2010 at 7:53 AM, Tim van der Molen <tbvdm@xs4all.nl> wrote:

Looks good to me.  I suspect sys/arch/m88k/include/va-m88k.h could use
some tweaking too, but it's different enough that I think it should be
tweaked (if necessary) separately.

ok guenther@

Previous thread: Re: MD5 Folding in kernel RNG by Theo de Raadt on Tuesday, December 28, 2010 - 3:39 pm. (2 messages)

Next thread: Line-by-line functionality for rev(1) by Vadim Zhukov on Tuesday, December 28, 2010 - 5:45 pm. (5 messages)