lkml.org 
[lkml]   [2020]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] KVM: x86: fix shift out of bounds reported by UBSAN
From
Date
On 22/12/20 19:31, David Laight wrote:
>> /*
>> * Use 2ULL to incorporate the necessary +1 in the shift; adding +1 in
>> * the shift count will overflow SHL's max shift of 63 if s=0 and e=63.
>> */
> A comment of the desired output value would be more use.
> I think it is:
> return 'e-s' ones followed by 's' zeros without shifting by 64.
>

What about a mix of the two:

/*
* Return 'e-s' ones followed by 's' zeros. Note that the
* apparently obvious 1ULL << (e - s + 1) can shift by 64 if
* s=0 and e=63, which is undefined behavior.
*/

Paolo

\
 
 \ /
  Last update: 2020-12-22 23:52    [W:0.300 / U:0.176 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site