Wireshark mailing list archives

Re: Removing string constants from assertions


From: Guy Harris <guy () alum mit edu>
Date: Tue, 4 Sep 2012 13:53:53 -0700


On Sep 4, 2012, at 1:39 PM, Evan Huus wrote:

I've noticed in several places the pattern of adding a message to
assertions in the form of a string constant:

g_assert(condition && "explanation");

This seems dangerous to me, primarily because if anyone ever mistypes
the && as a || then the assertion becomes dead code - it will always
pass.

Yes, that's risky.

Also (though less important):
- it doesn't really add any benefit over simply putting the message in
a comment - a developer will have to open up the code anyways to
figure out what the problem is

I'm not *entirely* sure that's the case; the message printed with the version of GLib on my machine (2.32.3) includes 
the entire assertion string:

        ERROR:sourcefile.c:{lineno}:{func}: assertion failed: ({test condition} && "{string}")

It Might Be Nice if there were a version of g_assert() that took two arguments - a condition and a description string - 
and printed

        ERROR:sourcefile.c:{lineno}:{func}: assertion failed: {test condition} : {description})

or something such as that, but there isn't.

We might be able to hack up a macro of that sort (with a helper routine, just as the existing g_assert macros have 
g_assertion_message_ helper routines).
___________________________________________________________________________
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: