Ethereal-dev: Re: [ethereal-dev] Hex dump problem?

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Thu, 27 Apr 2000 13:36:55 -0700 (PDT)
> Good catch. We use the isgraph() function to test whether a
> character has a printable representation, and isgraph() says that
> blanks do not have a printable representation.

Or, rather, it says that blanks aren't graphical characters.

"isprint()", however, should say that blanks are printable:

     isprint()      tests for any printing  character,  including
                    space (" ").
 
     isgraph()      tests  for  any  printing  character,  except
                    space.

(from Solaris 2.5.1, but the ANSI C standard says

	The "isprint" function tests for any printing character
	including space (' ').

and says earlier

	The term "printing character" refers to a member of a
	implementation-defined set of characters, each of which occupies
	one printing position on a display device; ...

so presumably that would *not* include tabs and form feeds and vertical
tabs and so on - it doesn't do so on Solaris 2.5.1, at least).

Attached is a patch that uses "isprint()" (rather than "isgraph()" plus
a check for space), and also uses, as per my other mail, "guchar" rather
than "gchar" for characters in "packet_hex_print()" (which should keep
it from exhibiting random behavior on bytes with the 8th bit set).
Index: proto_draw.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/gtk/proto_draw.c,v
retrieving revision 1.16
diff -c -r1.16 proto_draw.c
*** proto_draw.c	2000/04/27 17:04:37	1.16
--- proto_draw.c	2000/04/27 20:32:05
***************
*** 88,94 ****
  packet_hex_print(GtkText *bv, guint8 *pd, gint len, gint bstart, gint blen,
  		char_enc encoding) {
    gint     i = 0, j, k, cur;
!   gchar    line[128], hexchars[] = "0123456789abcdef", c = '\0';
    GdkFont *cur_font, *new_font;
    gint	   bend = -1;
  
--- 88,94 ----
  packet_hex_print(GtkText *bv, guint8 *pd, gint len, gint bstart, gint blen,
  		char_enc encoding) {
    gint     i = 0, j, k, cur;
!   guchar   line[128], hexchars[] = "0123456789abcdef", c = '\0';
    GdkFont *cur_font, *new_font;
    gint	   bend = -1;
  
***************
*** 155,161 ****
  	      else {
  		      g_assert_not_reached();
  	      }
!               line[cur++] = (isgraph(c) || c == ' ') ? c : '.';
        } else {
          line[cur++] = ' ';
        }
--- 155,161 ----
  	      else {
  		      g_assert_not_reached();
  	      }
!               line[cur++] = (isprint(c)) ? c : '.';
        } else {
          line[cur++] = ' ';
        }