chiark / gitweb /
integer arithmetic types: do not use unsigned for lengths
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jun 2011 21:34:09 +0000 (22:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jun 2011 11:07:26 +0000 (12:07 +0100)
commit1caa23ff879cec7f8f36b32a987f0610291ef177
treeacb2511a1dd990971d254b24c4714cf27e49ac77
parent6fbd4b99bc50cf9cd54a1b6e2b2c96c4ba4a9b19
integer arithmetic types: do not use unsigned for lengths

In C it is not normally a good idea to use an unsigned integer type
for integer values, even if they are known not ever to be zero (for
example, because they are lengths).  This is because C unsigned
arithmetic has unhelpful behaviour when the values would become
negative.

In particular, comparing signed and unsigned integers, and doing
arithmetic (especially subtraction) when unsigned integers are
present, can be dangerous and lead to unexpected results.

So fix the resulting warnings (which are due to -Wsign-compare which
comes from -W) by making all lengths, counts (and iterators over them)
and return values from scanf be of signed types, usually int32_t
instead of uint32_t (but occasionally int).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
24 files changed:
conffile.c
conffile.fl
conffile_internal.h
dh.c
hackypar.c
hackypar.h
ipaddr.c
ipaddr.h
log.c
md5.c
netlink.c
netlink.h
random.c
rsa.c
secnet.c
secnet.h
serpent.c
sha1.c
site.c
slip.c
transform.c
tun.c
util.c
util.h