[Bug 207854] usr/src/sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c:1437: bad shift ?

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Oct 31 15:07:19 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207854

Gleb Popov <arrowd at FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arrowd at FreeBSD.org

--- Comment #1 from Gleb Popov <arrowd at FreeBSD.org> ---
Not sure how UL would help here, since unsigned long is also 32-bits. The
proper fix is to use tmpN modulo 32 as shift operand. Verified this on
standalone example:

#include <stdio.h>
#include <sys/types.h>

int main(int argc, char* argv[])
{
    uint32_t tmpN;
    int tmp;
    for (tmpN=7 ; tmpN<64; tmpN++ )
    {
        //tmp = (1<<(tmpN%32));
        tmp = (1UL<<(tmpN%32));
        printf("%d\n", tmp);
    }
    return 0;
}


Patch for the problem:

Index: sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c
===================================================================
--- sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c     (revision 353638)
+++ sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c     (working copy)
@@ -1468,7 +1468,7 @@
     for (tmpA=(uint32_t)(64*pres) ; tmpA<128*pres; tmpA += pres )
         for (tmpN=7 ; tmpN<64; tmpN++ )
         {
-            tmp = ABS((int)(slope - tmpA/(1<<tmpN)));
+            tmp = ABS((int)(slope - tmpA/(1UL<<(tmpN%32))));
             if (tmp < gap)
             {
                sa = tmpA;

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list