[splint-discuss] Warnings when using g_assert

Michael Wojcik Michael.Wojcik at MicroFocus.com
Wed Oct 11 09:59:25 EDT 2006


> From: splint-discuss-bounces at cs.virginia.edu 
> [mailto:splint-discuss-bounces at cs.virginia.edu] On Behalf Of 
> Jeremy Cowgar
> Sent: Wednesday, 11 October, 2006 07:18
> 
> When I use g_assert:
> 
> g_assert (g_file_test ("config.ini", G_FILE_TEST_EXISTS) == 0);
> 
>   I get 3 warnings:
> 
> main.c:16:6: Test expression for if not boolean, type int: 1
>    Test expression type is not boolean or int. (Use -predboolint to  
> inhibit
>    warning)
> main.c:16:103: Null storage passed as non-null param: g_log (((gchar  
> *)0), ...)
>    A possibly null pointer is passed as a parameter corresponding to  
> a formal
>    parameter with no /*@null@*/ annotation.  If NULL may be used for  
> this
>    parameter, add a /*@null@*/ annotation to the function parameter  
> declaration.
>    (Use -nullpass to inhibit warning)
> main.c:16:345: Statement has no effect: (void)0
>    Statement has no visible effect --- no values are modified. (Use - 
> noeffect to
>    inhibit warning)
> 
> All three of these warnings are warnings I cannot do anything about w/

> o altering glib code, which I obviously do not want. I can disable  
> these checks via command line switches, but I don't want to because I

> want to be able to detect these problems in my own code. Is there  
> another way of causing these warnings not to appear?

You could put:

	/*@-predboolint -nullpass -noeffect@*/

before each use of g_assert, and:

	/*@=predboolint =nullpass =noeffect@*/

after each of them.

If that's onerous, use the standard assert macro, or define your own.
You don't say why you're using g_assert rather than assert, so we can't
tell if it's providing some critical functionality for you.  (I have no
experience with g_assert myself; I don't believe assertions are an
appropriate error-handling mechanism, so I don't use them.  The GLib
reference I just checked gives no indication that g_assert does anything
special.)

-- 
Michael Wojcik
Principal Software Systems Developer
Micro Focus

michael.wojcik at microfocus.com
9420 Key West Avenue
Rockville, MD 20850
Direct: 517 676 0892
What would you like Micro Focus to do for you? Contribute your view by
visiting
http://www.microfocus.com/CustomerInsight.asp



More information about the splint-discuss mailing list