Re: [PATCH] virSocketAddrPrefixToNetmask: Prevent undefined behaviour on bitshifts on signed integer

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

 



On Wed, Jun 18, 2025 at 08:31:36AM +0200, Peter Krempa via Devel wrote:
> From: Peter Krempa <pkrempa@xxxxxxxxxx>
> 
> Shifting bits into the sign bit is undefined behaviour in C although
> both gcc and clang handle it as expected.
> 
> Since the value is used as unsigned convert it to unsigned int. For code
> readability use 'if' statement instead of a ternary.
> 
> Closes: https://gitlab.com/libvirt/libvirt/-/issues/785
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/util/virsocketaddr.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@xxxxxxxxxx>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux