Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-bugs: [Wireshark-bugs] [Bug 7825] New: Explicitly declare/cast 'unsigned <variable>' a

Date: Tue, 9 Oct 2012 10:55:45 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7825

           Summary: Explicitly declare/cast 'unsigned <variable>' as
                    'unsigned int <variable>'
           Product: Wireshark
           Version: 1.8.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Minor
          Priority: Low
         Component: Common utilities (libwsutil)
        AssignedTo: bugzilla-admin@xxxxxxxxxxxxx
        ReportedBy: wp02855@xxxxxxxxx


Created attachment 9327
  --> https://bugs.wireshark.org/bugzilla/attachment.cgi?id=9327
contains all the patch files (diff -u format) listed in the description section
above

Build Information:
Build Information via wireshark -v:

odie:/usr/local/src/wireshark-1.8.2 # ./wireshark -v
wireshark 1.8.2 (SVN Rev Unknown from unknown)

Copyright 1998-2012 Gerald Combs <gerald@xxxxxxxxxxxxx> and contributors.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Compiled (64-bit) with GTK+ 2.22.1, with Cairo 1.10.2, with Pango 1.28.3, with
GLib 2.28.0, with libpcap, with libz 1.2.5, without POSIX capabilities, without
SMI, without c-ares, without ADNS, without Lua, without Python, with GnuTLS
2.8.6, with Gcrypt 1.4.6, with MIT Kerberos, without GeoIP, without PortAudio,
with AirPcap.

Running on Linux 2.6.37.6-0.7-desktop, with locale POSIX, with libpcap version
1.1.1, with libz 1.2.5, GnuTLS 2.8.6, Gcrypt 1.4.6, without AirPcap.

Built using gcc 4.5.1 20101208 [gcc-4_5-branch revision 167585].

--
In reviewing variable declarations and casts used in Wireshark 1.8.2,
I found some instances where the declaration of 'unsigned <foo>' was
used, and in some places 'unsigned int <foo>' is used.  The patches
below are designed to explicitly define 'unsigned <foo>' as 
'unsigned int <foo>' so that consistency is maintained.

I know that in C the definition of 'unsigned <foo>' is the same
as 'unsigned int <foo>', but in the code, the bulk of the variable
declarations and casts are of the form 'unsigned int <foo>'.

In Wireshark 1.8.2/1.8.3 modifications are needed in files:

--- 5views.c.orig       2012-10-08 16:36:20.111690963 -0700
+++ 5views.c    2012-10-08 16:36:35.023267209 -0700
@@ -367,7 +367,7 @@
        if (encap == WTAP_ENCAP_PER_PACKET)
                return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;

-       if (encap < 0 || (unsigned) encap >= NUM_WTAP_ENCAPS ||
wtap_encap[encap] == -1)
+       if (encap < 0 || (unsigned int) encap >= NUM_WTAP_ENCAPS ||
wtap_encap[encap] == -1)
                return WTAP_ERR_UNSUPPORTED_ENCAP;

        return 0;

--- dfilter-macro.c.orig        2012-10-08 15:55:21.355860063 -0700
+++ dfilter-macro.c     2012-10-08 15:55:39.626792361 -0700
@@ -581,7 +581,7 @@
        return d;
 }

-static gboolean macro_name_chk(void* r _U_, const char* in_name, unsigned
name_len, const void* u1 _U_, const void* u2 _U_, const char** error) {
+static gboolean macro_name_chk(void* r _U_, const char* in_name, unsigned int
name_len, const void* u1 _U_, const void* u2 _U_, const char** error) {
        guint i;

        if (name_len == 0) {

--- diam_dict.h.orig    2012-10-08 15:52:35.478330035 -0700
+++ diam_dict.h 2012-10-08 15:53:04.663414665 -0700
@@ -27,7 +27,7 @@

 struct _ddict_namecode_t {
        char* name;
-       unsigned code;
+       unsigned int code;
        struct _ddict_namecode_t* next;
 };

@@ -38,7 +38,7 @@
 typedef struct _ddict_vendor_t {
        char* name;
        char* desc;
-       unsigned code;
+       unsigned int code;
        struct _ddict_vendor_t* next;
 } ddict_vendor_t;

@@ -47,7 +47,7 @@
        char* description;
        char* vendor;
        char* type;
-       unsigned code;
+       unsigned int code;
        ddict_gavp_t* gavps;
        ddict_enum_t* enums;
        struct _ddict_avp_t* next;
@@ -62,7 +62,7 @@
 typedef struct _ddict_cmd_t {
        char* name;
        char* vendor;
-       unsigned code;
+       unsigned int code;
        struct _ddict_cmd_t* next;
 } ddict_cmd_t;

--- file_access.c.orig  2012-10-08 16:37:06.249569622 -0700
+++ file_access.c       2012-10-08 16:37:26.151669107 -0700
@@ -1456,7 +1456,7 @@

 #ifdef HAVE_LIBZ
        if (wdh->compressed) {
-               nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned)
bufsize);
+               nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned
int) bufsize);
                /*
                 * gzwfile_write() returns 0 on error.
                 */

--- file_wrappers.c.orig        2012-10-08 16:37:56.930923269 -0700
+++ file_wrappers.c     2012-10-08 16:41:39.339424607 -0700
@@ -111,12 +111,12 @@
        int fd;                 /* file descriptor */
        gint64 raw_pos;         /* current position in file (just to not call
lseek()) */
        gint64 pos;             /* current position in uncompressed data */
-       unsigned size;          /* buffer size */
+       unsigned int size;      /* buffer size */
        unsigned char *in;      /* input buffer */
        unsigned char *out;     /* output buffer (double-sized when reading) */
        unsigned char *next;    /* next output data to deliver or write */

-       unsigned have;          /* amount of output data unused at next */
+       unsigned int have;      /* amount of output data unused at next */
        int eof;                /* true if end of input file reached */
        gint64 start;           /* where the gzip data started, for rewinding
*/
        gint64 raw;             /* where the raw data started, for seeking */
@@ -178,7 +178,7 @@
        if (state->err)
                return -1;
        if (state->eof == 0) {
-               if (raw_read(state, state->in, state->size, (unsigned
*)&(state->avail_in)) == -1)
+               if (raw_read(state, state->in, state->size, (unsigned int
*)&(state->avail_in)) == -1)
                        return -1;
                state->next_in = state->in;
        }
@@ -341,7 +341,7 @@
        int ch;

        val = GZ_GETC();
-       val += (unsigned)GZ_GETC() << 8;
+       val += (unsigned int)GZ_GETC() << 8;
        val += (guint32)GZ_GETC() << 16;
        ch = GZ_GETC();
        if (ch == -1) {
@@ -502,7 +502,7 @@
                        unsigned int ready = count2 - strm->avail_out;

                        if (ready < ZLIB_WINSIZE) {
-                               unsigned left = ZLIB_WINSIZE - cur->pos;
+                               unsigned int left = ZLIB_WINSIZE - cur->pos;

                                if (ready >= left) {
                                        memcpy(cur->window + cur->pos, buf2,
left);
@@ -718,14 +718,14 @@
 static int
 gz_skip(FILE_T state, gint64 len)
 {
-       unsigned n;
+       unsigned int n;

        /* skip over len bytes or reach end-of-file, whichever comes first */
        while (len)
                if (state->have) {
                        /* We have stuff in the output buffer; skip over
                           it. */
-                       n = (gint64)state->have > len ? (unsigned)len :
state->have;
+                       n = (gint64)state->have > len ? (unsigned int)len :
state->have;
                        state->have -= n;
                        state->next += n;
                        state->pos += n;
@@ -902,7 +902,7 @@
 file_seek(FILE_T file, gint64 offset, int whence, int *err)
 {
        struct fast_seek_point *here;
-       unsigned n;
+       unsigned int n;

        /* can only seek from start or relative to current position */
        if (whence != SEEK_SET && whence != SEEK_CUR) {
@@ -926,7 +926,7 @@
                 * To squelch compiler warnings, we cast the
                 * result.
                 */
-               unsigned had = (unsigned)(file->next - file->out);
+               unsigned int had = (unsigned int)(file->next - file->out);
                if (-offset <= had) {
                        /*
                         * Offset is negative, so -offset is
@@ -940,7 +940,7 @@
                         * would want, so we cast -offset
                         * instead.)
                         */
-                       unsigned adjustment = (unsigned)(-offset);
+                       unsigned int adjustment = (unsigned)(-offset);
                        file->have += adjustment;
                        file->next -= adjustment;
                        file->pos -= adjustment;
@@ -1069,7 +1069,7 @@
        }

        /* skip what's in output buffer (one less gzgetc() check) */
-       n = (gint64)file->have > offset ? (unsigned)offset : file->have;
+       n = (gint64)file->have > offset ? (unsigned int)offset : file->have;
        file->have -= n;
        file->next += n;
        file->pos += n;
@@ -1129,7 +1129,7 @@
 int 
 file_read(void *buf, unsigned int len, FILE_T file)
 {
-       unsigned got, n;
+       unsigned int got, n;

        /* if len is zero, avoid unnecessary operations */
        if (len == 0)
@@ -1208,7 +1208,7 @@
 char *
 file_gets(char *buf, int len, FILE_T file)
 {
-       unsigned left, n;
+       unsigned int left, n;
        char *str;
        unsigned char *eol;

@@ -1231,7 +1231,7 @@
           append a terminating zero to the string (we don't check for a zero
in
           the contents, let the user worry about that) */
        str = buf;
-       left = (unsigned)len - 1;
+       left = (unsigned int)len - 1;
        if (left) do {
                /* assure that something is in the output buffer */
                if (file->have == 0) {
@@ -1257,7 +1257,7 @@
                n = file->have > left ? left : file->have;
                eol = (unsigned char *)memchr(file->next, '\n', n);
                if (eol != NULL)
-                       n = (unsigned)(eol - file->next) + 1;
+                       n = (unsigned int)(eol - file->next) + 1;

                /* copy through end-of-line, or remainder if not found */
                memcpy(buf, file->next, n);
@@ -1353,8 +1353,8 @@
 struct wtap_writer {
     int fd;                 /* file descriptor */
     gint64 pos;             /* current position in uncompressed data */
-    unsigned size;          /* buffer size, zero if not allocated yet */
-    unsigned want;          /* requested buffer size, default is GZBUFSIZE */
+    unsigned int size;      /* buffer size, zero if not allocated yet */
+    unsigned int want;      /* requested buffer size, default is GZBUFSIZE */
     unsigned char *in;      /* input buffer */
     unsigned char *out;     /* output buffer (double-sized when reading) */
     unsigned char *next;    /* next output data to deliver or write */
@@ -1466,7 +1466,7 @@
 gz_comp(GZWFILE_T state, int flush)
 {
     int ret, got;
-    unsigned have;
+    unsigned int have;
     z_streamp strm = &(state->strm);

     /* allocate memory if this is the first time through */
@@ -1480,14 +1480,14 @@
            doing Z_FINISH then don't write until we get to Z_STREAM_END */
         if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
             (flush != Z_FINISH || ret == Z_STREAM_END))) {
-            have = (unsigned)(strm->next_out - state->next);
+            have = (unsigned int)(strm->next_out - state->next);
             if (have) {
                got = write(state->fd, state->next, have);
                if (got < 0) {
                     state->err = errno;
                     return -1;
                 }
-                if ((unsigned)got != have) {
+                if ((unsigned int)got != have) {
                     state->err = WTAP_ERR_SHORT_WRITE;
                     return -1;
                 }
@@ -1521,11 +1521,11 @@
 /* Write out len bytes from buf.  Return 0, and set state->err, on
    failure or on an attempt to write 0 bytes (in which case state->err
    is Z_OK); return the number of bytes written on success. */
-unsigned
-gzwfile_write(GZWFILE_T state, const void *buf, unsigned len)
+unsigned int
+gzwfile_write(GZWFILE_T state, const void *buf, unsigned int len)
 {
-    unsigned put = len;
-    unsigned n;
+    unsigned int put = len;
+    unsigned int n;
     z_streamp strm;

     strm = &(state->strm);

--- i4btrace.c.orig     2012-10-08 16:42:37.165537523 -0700
+++ i4btrace.c  2012-10-08 16:43:27.637869328 -0700
@@ -54,9 +54,9 @@
  * Test some fields in the header to see if they make sense.
  */
 #define        I4B_HDR_IS_OK(hdr) \
-       (!((unsigned)hdr.length < 3 || (unsigned)hdr.length > 16384 || \
-           (unsigned)hdr.unit > 4 || (unsigned)hdr.type > 4 || \
-           (unsigned)hdr.dir > 2 || (unsigned)hdr.trunc > 2048))
+       (!((unsigned int)hdr.length < 3 || (unsigned int)hdr.length > 16384 ||
\
+           (unsigned int)hdr.unit > 4 || (unsigned int)hdr.type > 4 || \
+           (unsigned int)hdr.dir > 2 || (unsigned int)hdr.trunc > 2048))

 int i4btrace_open(wtap *wth, int *err, gchar **err_info)
 {

--- irda-appl.h.orig    2012-10-08 16:26:20.657342746 -0700
+++ irda-appl.h 2012-10-08 16:27:06.994239508 -0700
@@ -50,8 +50,8 @@
     DATA_PDU
 } pdu_type_t;

-typedef gboolean (*ias_value_dissector_t)(tvbuff_t* tvb, unsigned offset,
packet_info* pinfo, proto_tree* tree,
-                                          unsigned list_index, guint8
attr_type);
+typedef gboolean (*ias_value_dissector_t)(tvbuff_t* tvb, unsigned int offset,
packet_info* pinfo, proto_tree* tree,
+                                          unsigned int list_index, guint8
attr_type);

 typedef const struct ias_attr_dissector {
     const char*             attr_name;
@@ -64,14 +64,14 @@
 } ias_class_dissector_t;


-extern gboolean check_iap_octet_result(tvbuff_t* tvb, proto_tree* tree,
unsigned offset,
+extern gboolean check_iap_octet_result(tvbuff_t* tvb, proto_tree* tree,
unsigned int offset,
                                        const char* attr_name, guint8
attr_type);
-extern guint8 check_iap_lsap_result(tvbuff_t* tvb, proto_tree* tree, unsigned
offset,
+extern guint8 check_iap_lsap_result(tvbuff_t* tvb, proto_tree* tree, unsigned
int offset,
                                     const char* attr_name, guint8 attr_type);

 extern void add_lmp_conversation(packet_info* pinfo, guint8 dlsap, gboolean
ttp, dissector_t proto_dissector);

-extern unsigned dissect_param_tuple(tvbuff_t* tvb, proto_tree* tree, unsigned
offset);
+extern unsigned dissect_param_tuple(tvbuff_t* tvb, proto_tree* tree, unsigned
int offset);

 /*
  * Protocol exports.

--- iseries.c.orig      2012-10-08 16:44:03.688678504 -0700
+++ iseries.c   2012-10-08 16:44:21.688582469 -0700
@@ -212,7 +212,7 @@
    * Check if this is a UNICODE formatted file by scanning for the magic
string
    */
   offset=0;
-  while ((unsigned)offset < (ISERIES_LINE_LENGTH - (sizeof unicodemagic)))
+  while ((unsigned int)offset < (ISERIES_LINE_LENGTH - (sizeof unicodemagic)))
     {
       if (memcmp (magic + offset, unicodemagic, sizeof unicodemagic) == 0) {
         if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)

--- md5.c.orig  2012-10-08 15:53:59.298185240 -0700
+++ md5.c       2012-10-08 15:54:40.658558752 -0700
@@ -58,7 +58,7 @@
 /*
  * Note: this code is harmless on little-endian machines.
  */
-static void byteReverse(guint32 *buf, unsigned longs)
+static void byteReverse(guint32 *buf, unsigned int longs)
 {
     guint32 t;
     do {
@@ -141,7 +141,7 @@
  */
 void md5_finish(md5_state_t *ctx, unsigned char digest[16])
 {
-    unsigned count;
+    unsigned int count;
     unsigned char *p;

     /* Compute number of bytes mod 64 */

-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.