Re: Suggestion on "int len" sanity

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

 



Willy Tarreau wrote:

On the other hand, when a variable is named "len" or "length", it is usually used for length and never should go negative. So could I suggest that the declarations of these variables to be uniformized to "size_t", via a gradual but sysmatic cleanup?

Probably true for most cases, but be careful of code which would use
-1 to report some errors if such thing exists.

I agree that they are probably not all replaceable, and care must be taken.

Examples:

1. In the types of sys_[gs]ethostname, sys_[gs]etdomainname, "int len" could be replaced
by "unsigned int" or "size_t" and sanity check simplified.

2. In mm/shmem.c, shmem_symlink(), we have "len = strlen(symname) + 1;". Although it is highly
improbable that strlen(symname) overflows, it is more correct to declare "size_t len;".

3. The similar situation occurs in fs/namei.c, vfs_readlink(). Here it does not matter if len
is declared to be unsigned, but for size_t, we have to take care about the size of size_t.

--

XIAO Gang (~{P$8U~})                          [email protected]
home page: pcmath126.unice.fr/xiao.html


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux