while or for ?

frederic heem frederic.heem at telsey.it
Tue Oct 17 01:22:11 PDT 2006


Hi,
While hinting a memory leak, I came across a weird construct which leads to a 
bug:
  /* Find empty slot */
  i = 0;
  while (message_cache[i] != NULL)
    ++i;

when the message_cache array is full, the index i will be out of range, hence 
message_cache[i] will point where it can't.
IMHO, a for loop shall be used in this case.
Frederic Heem



More information about the dbus mailing list