tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: why cast to char* through void*



At Thu, 2 Jul 2009 13:42:56 -0400, christos%zoulas.com@localhost (Christos 
Zoulas) wrote:
Subject: Re: why cast to char* through void*
> 
> On Jul 2, 12:30pm, woods%planix.com@localhost ("Greg A. Woods") wrote:
> -- Subject: Re: why cast to char* through void*
> 
> | As I said, the cast through void* is not necessary here on at least i386
> | neither for generating the correct result, nor for shutting up GCC.
> 
> Did you try it? It breaks lint.

No, I didn't try lint.  But lint didn't "break" -- lint warnings are
normal in many cases and should NOT be hidden or obscured by even more
questionable practises.


> Yes, lint is broken and should not complain
> in that case, but until it is fixed...
> 
> /usr/src/lib/libutil/login_cap.c(521): warning: pointer casts may be 
> troublesome [247]

Well, lint may in fact be right.  Pointer casts _may_ be troublesome.

The correct action would be to tell lint that in this case the cast is
not going to be a problem because the programmer does know better.  ;-)

--- login_cap.c 10 Feb 2007 12:57:39 -0500      1.25
+++ login_cap.c 02 Jul 2009 14:33:09 -0400      
@@ -517,8 +517,9 @@
        if (!res)
                return -1;
        
-       ptr = (char *)(void *)&res[count];
-       (void)strcpy(ptr, str);
+       /* LINTED (we are creating an array of pointers into the same storage) 
*/
+       ptr = (char *) &res[count];
+       (void) strcpy(ptr, str);
 
        /* split string */
        for (i = 0; (res[i] = stresep(&ptr, stop, '\\')) != NULL; )

-- 
                                                Greg A. Woods
                                                Planix, Inc.

<woods%planix.com@localhost>       +1 416 218-0099        http://www.planix.com/

Attachment: pgperFJq8T7fM.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index