NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/50745: src/usr.bin/ftp/cmds.c:1974]: (style) Array index 'i' is used before limits check.



The following reply was made to PR bin/50745; it has been noted by GNATS.

From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: bin/50745: src/usr.bin/ftp/cmds.c:1974]: (style) Array index 'i'
 is used before limits check.
Date: Sat, 6 Feb 2016 19:40:39 +0000

 On Tue, Feb 02, 2016 at 10:30:00AM +0000, d%NetBSD.org@localhost wrote:
  > Source code is
  > 
  >       for (i = 0; *(ntin + i) && i < 16; i++) {
  > 
  > Maybe something like
  > 
  >       for (i = 0; (i < 16) && *(ntin + i); i++) {
  > 
  > might be better.
 
 There's more to it than that; the array bound is actually 17, not 16.
 
 It isn't clear to me that it makes sense for the limit to be either 16
 or 17 and not, say, 128, and it looks like much of the logic involved
 in handling this feature is screwy. But certainly "16" shouldn't be
 getting written literally inline halfway across the source from the
 definition of the array.
 
 I'm inclined to just rewrite the feature and fix up the logic, but I'm
 not sure if there are reasons for some of these properties.
 
 -- 
 David A. Holland
 dholland%netbsd.org@localhost
 


Home | Main Index | Thread Index | Old Index