lkml.org 
[lkml]   [2019]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [RFC PATCH] coccinelle: check for integer overflow in binary search
    From
    Date
    > +identifier l, h, m;

    Can expressions make sense for these metavariables?


    > +@@
    > +(
    > + while (\(l < h\|l <= h\|(h - l) > 1\|(l + 1) < h\|l < (h - 1)\)) {
    > + ...
    > +(
    > + ((l + h)@p / c)
    > +|
    > + ((l + h)@p >> c)
    > +)
    > + ...
    > + }

    * I suggest again to look at further possibilities to reduce undesirable
    code duplication also together with the usage of SmPL disjunctions.

    * The condition specification might be easier to read with a few
    additional spaces (or the following variant).

    * The SmPL ellipses will probably need further considerations.


    +@@
    +(
    + while (
    +( l \( < \| <= \) h
    +| (h - l) > 1
    +| (h - 1) > l
    +| (l + 1) < h
    +) )
    + {
    + <+...
    + ((l + h)@p \( / \| >> \) c)
    + ...+>
    + }


    > +@script:python depends on report@
    > +p << r.p;
    > +@@
    > +
    > +msg="WARNING: custom implementation of bsearch is error-prone. "
    > +msg+="Consider using lib/bsearch.c or fix the midpoint calculation "
    > +msg+="as 'm = l + (h - l) / 2;' to prevent the arithmetic overflow."
    > +coccilib.report.print_report(p[0], msg)

    The Linux coding style supports to put a long string literal also into a single line.
    Thus I find such a message construction nicer without the extra variable “msg”.

    Regards,
    Markus

    \
     
     \ /
      Last update: 2019-09-05 14:35    [W:4.478 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site