Wireshark mailing list archives
Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c
From: Gerald Combs <gerald () wireshark org>
Date: Thu, 17 Feb 2011 09:49:58 -0800
On 2/17/11 1:23 AM, Guy Harris wrote:
To correct this warning, examine the pointer for null value as shown in the following code: #include <malloc.h> void f( ) { char *p = ( char * )malloc ( 10 ); if ( p ) { *p = '\0'; // code ... free( p ); } } " (not "if ( p != NULL )", just "if ( p )").
That doesn't produce any errors with "/analyze". The following tests compile without errors as well: -------- #include <malloc.h> void f( ) { char *p; if (p = ( char * ) malloc( 10 )) { *p = '\0'; free( p ); } } -------- -------- #include <malloc.h> #include <stdlib.h> void f( ) { char *p; int testval = 1; if (((p = ( char * ) malloc( 10 )) != NULL) && testval) { *p = '\0'; free( p ); } } -------- However this produces an error: -------- #include <malloc.h> void f( ) { char *p; int testval = 1; if ((p = ( char * ) malloc( 10 )) && testval) { *p = '\0'; free( p ); } } -------- test.c(9) : warning C6011: Dereferencing NULL pointer 'p': Lines: 5, 6, 8, 9 -- Join us for Sharkfest ’11! · Wireshark® Developer and User Conference Stanford University, June 13-16 · http://sharkfest.wireshark.org ___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Stig Bjørlykke (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Guy Harris (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Guy Harris (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Guy Harris (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Gerald Combs (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Guy Harris (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Guy Harris (Feb 17)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Jeff Morriss (Feb 17)
- Yoda style conditions (was: Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c) Steffen DETTMER (Feb 23)
- Re: Yoda style conditions (was: Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c) Guy Harris (Feb 23)
- Re: Yoda style conditions (was: Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c) Steffen DETTMER (Feb 24)
- Re: Yoda style conditions Jeff Morriss (Feb 24)
- Re: [Wireshark-commits] rev 35975: /trunk/epan/dfilter/ /trunk/epan/dfilter/: dfilter-macro.c dfilter.c Guy Harris (Feb 17)