[PATCH] D46274: [Support] Harden JSON against invalid UTF-8.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 10 04:53:47 PDT 2018


sammccall marked 5 inline comments as done.
sammccall added inline comments.


================
Comment at: include/llvm/Support/JSON.h:302
+  Value(std::string V) : Type(T_String) {
+    if (!LLVM_LIKELY(isUTF8(V))) {
+      assert(false && "Invalid UTF-8 in value used as JSON");
----------------
dexonsmith wrote:
> benhamilton wrote:
> > Seems like flipping the check is clearer:
> > 
> > ```
> > if (LLVM_UNLIKELY(!isUTF8(V)) {
> > ```
> > 
> Moreover, `__builtin_expect` doesn't work if it's not the top-level condition, and `LLVM_LIKELY` and `LLVM_UNLIKELY` are both using it.
Interesting! Naive test suggests this isn't always true for clang, though probably is for GCC:
https://godbolt.org/g/vek4jo

Done in any case.


Repository:
  rL LLVM

https://reviews.llvm.org/D46274





More information about the llvm-commits mailing list