Messages in this thread | | | Date | Thu, 02 Jun 2005 09:28:55 +0200 | From | XIAO Gang <> | Subject | Re: Suggestion on "int len" sanity |
| |
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~}) xiao@unice.fr 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |