ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] g_snprintf() and sizeof

From: Bill Meier <wmeier@xxxxxxxxxxx>
Date: Thu, 19 Mar 2009 15:09:22 -0400
Guy Harris wrote:
On Mar 19, 2009, at 10:44 AM, wmeier@xxxxxxxxxxxxx wrote:

-As suggested by Jakub Zawadzki: use sizeof(...) rather than a numeric constant in various places;

Warning: g_snprintf()'s function signature has an annoying botch in it - the size argument is a gulong, not a gsize.

Not a problem in the UN*X and Windows ILP32 environment and in the UN*X LP64 environment, but it causes the Microsoft compiler to (correctly) warn about a conversion from a 64-bit integer to a 32-bit integer in the Windows LLP64 environment. Cast sizeof - or any other size_t value - to (gulong) before passing it as the length argument to g_snprintf().
___________________________________________________________________________


Ouch !

As you know, sizeof is used in *many* places in Wireshark when calling g_snprint. This was true even before the recent changes.

Is there any other approach than adding an explicit cast to each and every usage of sizeof when calling g_snprintf & friends ??

Thoughts ??

(If necessary, I'll go through and change to use a cast in all the required places. It shouldn't be too hard with Emacs).

Bill