[PATCH] D97129: [Support] unsafe pointer arithmetic in llvm_regcomp()

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 25 17:44:09 PST 2022


MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

The clang-format diagnostic is because of TAB. The OpenBSD version (https://github.com/openbsd/src/blob/master/lib/libc/regex/regcomp.c) uses TAB and our copy probably should just match.

I verified that this does port the OpenBSD change, but please make sure @vitalybuka is happy as well.



================
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)
----------------
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.


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