HomeFreeBSD

libc: fix cases of undefined behavior.

Description

libc: fix cases of undefined behavior.

These were found by the Undefined Behavious GsoC project at NetBSD:

Avoid undefined behavior in ftok(3)

Do not change the signedness bit with a left shift operation.
Cast to unsigned integer to prevent this.

ftok.c:56:10, left shift of 123456789 by 24 places cannot be represented
in type 'int'
ftok.c:56:10, left shift of 4160 by 24 places cannot be represented in
type 'int'

Avoid undefined behavior in an inet_addr.c

Do not change the signedness bit with a left shift operation.
Cast to unsigned integer to prevent this.

inet_addr.c:218:20, left shift of 131 by 24 places cannot be represented
in type 'int'

Detected with micro-UBSan in the user mode.

Obtained from: NetBSD
MFC after: 2 weeks

Details

Provenance
pfgAuthored on
Parents
rS337421: MFC r336957:
Branches
Unknown
Tags
Unknown