Redundant validity check in stock code.

From: Thomas Arp (t_arp@stofanet.dk)
Date: 07/25/02


Hey all,

A couple of places in the code, there is a redundant check for
validity of a variable. In all cases, the check refers to

nlen < 0

where nlen is a size_t (which is unsigned). Also, as you can see
from the below code, nlen must be initialized to a positive number
(or 0) before this line, as snprintf() always returns a positive
number or 0.

utils.c:307:
size_t sprintbit(....)
{
  size_t len = 0, nlen;
  long nr;

  *result = '\0';

  for (nr = 0; bitvector && len < reslen; bitvector >>= 1) {
    if (IS_SET(bitvector, 1)) {
      nlen = snprintf(result + len, reslen - len, "%s ",
           *names[nr] != '\n' ? names[nr] : "UNDEFINED");
-->   if (len + nlen >= reslen || nlen < 0)
        break;
      len += nlen;
    }

act.wizard.c:2007:
act.wizard.c:2088:
act.wizard.c:2101:
act.wizard.c:2114:
spec_procs.c:142:

Same thing. Removing the '|| nlen < 0' can be done safely.

Welcor

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT