[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 10 14:27:40 PDT 2018


george.karpenkov requested changes to this revision.
george.karpenkov added inline comments.
This revision now requires changes to proceed.


================
Comment at: lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp:164
+  // - sizeof(dst)
+  if (Append && isSizeof(LenArg, DstArg))
+    return true;
----------------
george.karpenkov wrote:
> george.karpenkov wrote:
> > I am confused on what is happening in this branch and why is it bad. Could we add a commend?
> Sorry I'm still confused about this branch: could you clarify?
Ah, OK, I see it needs one more byte due to null-termination.


================
Comment at: lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp:199
         uint64_t BufferLen = C.getTypeSize(Buffer) / 8;
-        if ((BufferLen - DstOff) < ILRawVal)
-          return true;
+        auto RemainingBufferLen = BufferLen - DstOff;
+        if (Append) {
----------------
Probably better expressed as:

```
if (Append)
  RemainingBufferLen -= 1;
```

Then you don't need branching.


https://reviews.llvm.org/D49722





More information about the cfe-commits mailing list