Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Terry Lambert

M. Warner Losh wrote:
 I've fixed a few of the low hanging fruit, but I don't know how to get
 rid of warnings like:
 
 const char *foo = blah;
 char *baz = foo;
 
 when I know they are safe.

Un-const foo.  The compiler assumes strings are const unless
you go out of your way to do -fwriteable-strings.  It will
fault on a non-writeable page if you try to muck with it.

-- Terry

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Georg-W Koltermann

Hi Warner,

a simple cast

  char *baz = (char*)foo;

works for me.

--
Regards,
Georg.

At Mon, 25 Feb 2002 21:59:23 -0700 (MST),
M. Warner Losh [EMAIL PROTECTED] wrote:
 
 In message: [EMAIL PROTECTED]
 Peter Wemm [EMAIL PROTECTED] writes:
 : There are a couple of offending files in the kernel still, and some
 : drivers. The things people are most likely to run into are:  usb, inet6,
 : and some drivers (twe, asr etc).
 
 I've fixed a few of the low hanging fruit, but I don't know how to get
 rid of warnings like:
 
 const char *foo = blah;
 char *baz = foo;
 
 when I know they are safe.
 
 Warner

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Peter Dufault

On Mon, Feb 25, 2002 at 11:35:12PM -0700, M. Warner Losh wrote:
 In message: [EMAIL PROTECTED]
 Mike Makonnen [EMAIL PROTECTED] writes:
 : On Mon, 2002-02-25 at 20:59, M. Warner Losh wrote:
 :  I've fixed a few of the low hanging fruit, but I don't know how to get
 :  rid of warnings like:
 :  
 :  const char *foo = blah;
 :  char *baz = foo;
 :  
 :  when I know they are safe.
 : 
 : Correct me if I'm wrong, but isn't the correct declaration:
 : 
 : const char foo[] = blah;
 : char baz[] = foo;
 
 You miss the point.  First, there's no  around foo.  Second, what I
 quoted was boiled down from a bunch of macros and such.  Third, the
 real example would be
 
 volatile int conspeed;
 int *foo = conspeed;
 
 Where foo is only accessed before all other accesses to conspeed.

When it is too twisty to fix at the moment I use macros such as:

#define BOGUSLY_CAST_AWAY_VOLATILITY(T,P) ((T)(unsigned int)(P))

...

volatile int conspeed; int *foo =
BOGUSLY_CAST_AWAY_VOLATILITY(int *, conspeed);

to surpress the warnings.  You can easily redefine the macro to get
them back so together with the discouraging name you're not sweeping
things under the rug.

I don't think there is a GCC attribute to get around this differently.

Peter

PS - this is a quick example, please no one comment on the size of
unsigned int or using gcc typeof instead, etc.

--
Peter Dufault ([EMAIL PROTECTED])   Realtime development, Machine control,
HD Associates, Inc.   Fail-Safe systems, Agency approval

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Garrett Wollman

On Mon, 25 Feb 2002 23:35:12 -0700 (MST), M. Warner Losh [EMAIL PROTECTED] said:

 volatile int conspeed;
 int *foo = conspeed;

The answer to this is

Not all warnings are indicative of errors.  It is unreasonable to
expect all warnings to be removed, since the compiler has insufficient
knowledge to be able to determine whether this usage is safe or not.

-GAWollman


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Bruce Evans

On Tue, 26 Feb 2002, Garrett Wollman wrote:

 On Mon, 25 Feb 2002 23:35:12 -0700 (MST), M. Warner Losh [EMAIL PROTECTED] said:

  volatile int conspeed;
  int *foo = conspeed;

 The answer to this is

 Not all warnings are indicative of errors.  It is unreasonable to
 expect all warnings to be removed, since the compiler has insufficient
 knowledge to be able to determine whether this usage is safe or not.

It should be possible to tell it to at least not convert individual
warnings to errors, using something like lint markup.  IIRC, TenDRA
uses #pragma for related things in its headers.

Bruce


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Peter Wemm

Peter Dufault wrote:
 On Mon, Feb 25, 2002 at 11:35:12PM -0700, M. Warner Losh wrote:
  In message: [EMAIL PROTECTED]
  Mike Makonnen [EMAIL PROTECTED] writes:
  : On Mon, 2002-02-25 at 20:59, M. Warner Losh wrote:
  :  I've fixed a few of the low hanging fruit, but I don't know how to get
  :  rid of warnings like:
  :  
  :  const char *foo = blah;
  :  char *baz = foo;
  :  
  :  when I know they are safe.
  : 
  : Correct me if I'm wrong, but isn't the correct declaration:
  : 
  : const char foo[] = blah;
  : char baz[] = foo;
  
  You miss the point.  First, there's no  around foo.  Second, what I
  quoted was boiled down from a bunch of macros and such.  Third, the
  real example would be
  
  volatile int conspeed;
  int *foo = conspeed;
  
  Where foo is only accessed before all other accesses to conspeed.
 
 When it is too twisty to fix at the moment I use macros such as:
 
 #define BOGUSLY_CAST_AWAY_VOLATILITY(T,P) ((T)(unsigned int)(P))
 
 ...
 
 volatile int conspeed; int *foo =
   BOGUSLY_CAST_AWAY_VOLATILITY(int *, conspeed);
 
 to surpress the warnings.  You can easily redefine the macro to get
 them back so together with the discouraging name you're not sweeping
 things under the rug.

In sys/cdefs.h, we have:

#define __DECONST(type, var)((type)(uintptr_t)(const void *)(var))

.. but bde threatened bodily harm for using it if I recall correctly.

There is also __DEVOLATILE() and __DEQUALIFY()

Cheers,
-Peter
--
Peter Wemm - [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
All of this is for nothing if we don't go to the stars - JMS/B5


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-26 Thread Bruce Evans

On Tue, 26 Feb 2002, Peter Wemm wrote:

 Peter Dufault wrote:
  When it is too twisty to fix at the moment I use macros such as:
 
  #define BOGUSLY_CAST_AWAY_VOLATILITY(T,P) ((T)(unsigned int)(P))
 
  ...
 
  volatile int conspeed; int *foo =
  BOGUSLY_CAST_AWAY_VOLATILITY(int *, conspeed);
 
  to surpress the warnings.  You can easily redefine the macro to get
  them back so together with the discouraging name you're not sweeping
  things under the rug.

 In sys/cdefs.h, we have:

 #define __DECONST(type, var)((type)(uintptr_t)(const void *)(var))

 .. but bde threatened bodily harm for using it if I recall correctly.

Sort of.  __DECONST() is not ugly enough, and even its implementations are
not ugly enough to be as correct as possible (spot the missing cast).

I was recently forced to fix a warning that was fixed using the
uintptr_t hack (missing a cast of course) in -current but not in my
version (pending a better fix).

Index: link_elf.c
===
RCS file: /home/ncvs/src/sys/kern/link_elf.c,v
retrieving revision 1.51
diff -u -2 -r1.51 link_elf.c
--- link_elf.c  16 Nov 2001 21:08:37 -  1.51
+++ link_elf.c  27 Feb 2002 06:34:38 -
@@ -839,8 +840,9 @@
 elf_file_t ef = (elf_file_t) file;

-#ifdef DDB
+#if defined(DDB)  defined(__ELF__)
 if (ef-gdb.l_ld) {
GDB_STATE(RT_DELETE);
-   free((void *)(uintptr_t)ef-gdb.l_name, M_LINKER);
+   /* XXX extreme ugliness to avoid a cast-qual warning: */
+   free((void *)(uintptr_t)(const void *)ef-gdb.l_name, M_LINKER);
link_elf_delete_gdb(ef-gdb);
GDB_STATE(RT_CONSISTENT);

Is this ugly enough?

Bruce


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-25 Thread Peter Wemm

There are a couple of offending files in the kernel still, and some
drivers. The things people are most likely to run into are:  usb, inet6,
and some drivers (twe, asr etc).

Yes, you will almost certainly need 'make -DNO_WERROR' for the short term.
But do take a look, there is some low hanging fruit there.

--- Forwarded Message

Date:Mon, 25 Feb 2002 14:04:33 -0800
From:Peter Wemm [EMAIL PROTECTED]
To:  [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: cvs commit: src/sys/conf kern.pre.mk

peter   2002/02/25 14:04:33 PST

  Modified files:
sys/conf kern.pre.mk 
  Log:
  Turn on -Werror by default.  This is is easily turned off, by either:
  - fix the warnings, they are there for a reason!
  - add -DNO_ERROR to your make(1) command.
  - add 'makeoptions NO_WERROR=true' to your kernel config.
  - add 'nowerror' to conf/files* that have warnings that should be fixed
due to tracking 3rd party vendor code.
  - add 'nowerror' to conf/files* where the warning is false due to a
compiler bug and fixing it with brute force would be too expensive.
  
  There are some very sloppy warnings in our kernel build, come on folks!
  
  'make release' uses -DNO_WERROR intentionally.
  
  Revision  ChangesPath
  1.8   +5 -5  src/sys/conf/kern.pre.mk


--- End of Forwarded Message



To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-25 Thread M. Warner Losh

In message: [EMAIL PROTECTED]
Peter Wemm [EMAIL PROTECTED] writes:
: There are a couple of offending files in the kernel still, and some
: drivers. The things people are most likely to run into are:  usb, inet6,
: and some drivers (twe, asr etc).

I've fixed a few of the low hanging fruit, but I don't know how to get
rid of warnings like:

const char *foo = blah;
char *baz = foo;

when I know they are safe.

Warner

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-25 Thread Mike Makonnen

On Mon, 2002-02-25 at 20:59, M. Warner Losh wrote:
 I've fixed a few of the low hanging fruit, but I don't know how to get
 rid of warnings like:
 
 const char *foo = blah;
 char *baz = foo;
 
 when I know they are safe.

Correct me if I'm wrong, but isn't the correct declaration:

const char foo[] = blah;
char baz[] = foo;

cheers,
mike makonnen



To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-25 Thread M. Warner Losh

In message: [EMAIL PROTECTED]
Mike Makonnen [EMAIL PROTECTED] writes:
: On Mon, 2002-02-25 at 20:59, M. Warner Losh wrote:
:  I've fixed a few of the low hanging fruit, but I don't know how to get
:  rid of warnings like:
:  
:  const char *foo = blah;
:  char *baz = foo;
:  
:  when I know they are safe.
: 
: Correct me if I'm wrong, but isn't the correct declaration:
: 
: const char foo[] = blah;
: char baz[] = foo;

You miss the point.  First, there's no  around foo.  Second, what I
quoted was boiled down from a bunch of macros and such.  Third, the
real example would be

volatile int conspeed;
int *foo = conspeed;

Where foo is only accessed before all other accesses to conspeed.

Warner

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd)

2002-02-25 Thread Peter Wemm

M. Warner Losh wrote:
 In message: [EMAIL PROTECTED]
 Peter Wemm [EMAIL PROTECTED] writes:
 : There are a couple of offending files in the kernel still, and some
 : drivers. The things people are most likely to run into are:  usb, inet6,
 : and some drivers (twe, asr etc).
 
 I've fixed a few of the low hanging fruit, but I don't know how to get
 rid of warnings like:
 
 const char *foo = blah;
 char *baz = foo;
 
 when I know they are safe.

char *baz = (char *)(uintptr_t)foo;

... will work, but isn't exactly pretty.  I vaguely recall being told that
it should be cast to void * first.. ie: 

char *baz = (char *)(uintptr_t)(const void *)foo;

 Warner
 

Cheers,
-Peter
--
Peter Wemm - [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
All of this is for nothing if we don't go to the stars - JMS/B5


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message