[PATCH] D97129: [Support] unsafe pointer arithmetic in llvm_regcomp()
    Vitaly Buka via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Jan 26 14:03:53 PST 2022
    
    
  
vitalybuka added inline comments.
================
Comment at: llvm/lib/Support/regcomp.c:252
 #define	PEEK2()	(*(p->next+1))
-#define	MORE()	(p->next < p->end)
-#define	MORE2()	(p->next+1 < p->end)
+#define	MORE()	(p->end - p->next > 0)
+#define	MORE2()	(p->end - p->next > 1)
----------------
MaskRay wrote:
> vitalybuka wrote:
> > I understand all but this line. I guess it had no UB there.
> I think this clause applies
> https://www.iso-9899.info/n1570.html#6.5.6p8 "...  If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined."
> 
> There was a UB.
I am aware of this rule, but I assume that end and next always "point to elements of the same array object, or one past the last element"
So old MORE2 violates the rule, but MORE does not.
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97129/new/
https://reviews.llvm.org/D97129
    
    
More information about the llvm-commits
mailing list