[PATCH] D87239: [analyzer][StdLibraryFunctionsChecker] Remove strcasecmp

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 7 09:06:34 PDT 2020


martong marked an inline comment as done.
martong added a comment.

In D87239#2259345 <https://reviews.llvm.org/D87239#2259345>, @steakhal wrote:

> I completely agree with you.
> I plan to further refactor the CStringChecker, but the related patches are pretty much stuck :D
>
> I think this workaround is fine for now.
> You might as well extend the corresponding parts of the CStringChecker to make the modelling more precise.
> It shouldn't be much of a hassle.
> What do you say about that?

I think the modeling is well done and precise. I mean, it seems like all of the constraints that I am removing here are handled in CStringChecker. It checks the pointer arguments whether they are null. Also, the length is checked in case of `strncasecmp`, here:

  if (IsBounded) {
    // Get the max number of characters to compare.
    const Expr *lenExpr = CE->getArg(2);
    SVal lenVal = state->getSVal(lenExpr, LCtx);
  
    // If the length is known, we can get the right substrings.
    if (const llvm::APSInt *len = svalBuilder.getKnownValue(state, lenVal)) {
      // Create substrings of each to compare the prefix.
      LeftStrRef = LeftStrRef.substr(0, (size_t)len->getZExtValue());
      RightStrRef = RightStrRef.substr(0, (size_t)len->getZExtValue());
      canComputeResult = true;
    }
  } else { .... }

So, the problem is rather that the constraint check should be done in checkPreCall, but that should be in an NFC refactoring.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87239/new/

https://reviews.llvm.org/D87239



More information about the cfe-commits mailing list