[omniORB] cosmetic bug in tcpSocketMTfactory.cc::dumpbuf

Christof Meerwald cmeerw@htl.fh-sbg.ac.at
Tue, 26 Oct 1999 21:12:28 +0200


Hi,

I think there is a cosmetic bug in dumpbuf (tcpSocketMTfactory.cc, Version
2.80 and 3.00pre1) - it sometimes forgets to print the ASCII representation
of the last 15/16 bytes and it may access the buffer at position sz+1.

Here is a fixed version (works for me, but the code still isn't very
readable...):

static void dumpbuf(unsigned char* buf, size_t sz)
{
  omni_mutex_lock sync(dumplock);
  // Dumping buffer
  unsigned int i = 0, k, j = 0;
  for (; i < sz; i+=2) {
    fprintf(stderr,"%02x%02x ", buf[i], (i+1 < sz) ? buf[i+1] : 0);
    j+=2;
    if (j % 16 == 0) {
      for (k=i-14; (k<i + 2) && (k < sz); k++)
	fprintf(stderr,"%c", (buf[k] < 32 || buf[k] > 126) ? '.' : buf[k]);
      fprintf(stderr,"\n");
    }
  }
  if (j % 16) {
    for (k=(j%16); k < 16; k+=2) fprintf(stderr,"     ");
    for (k=i-(j%16); (k < sz); k++)
      fprintf(stderr,"%c", (buf[k] < 32 || buf[k] > 126) ? '.' : buf[k]);
    fprintf(stderr,"\n");
  }
}



bye, Christof

-- 
Don't hate yourself in the morning... sleep until noon!