[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 22 06:13:09 PDT 2024


================
@@ -529,3 +529,37 @@ void nocrash_on_locint_offset(void *addr, void* from, struct S s) {
   size_t iAdd = (size_t) addr;
   memcpy(((void *) &(s.f)), from, iAdd);
 }
+
+//===----------------------------------------------------------------------===//
+// getentropy()
+//===----------------------------------------------------------------------===//
+
+int getentropy(void *d, size_t n);
+
+int getentropy0(void) {
+  char buf[16] = {0};
+
+  int r = getentropy(buf, sizeof(buf)); // no-warning
+  return r;
+}
+
+int getentropy1(void) {
+  char buf[257] = {0};
+
+  int r = getentropy(buf, 256); // no-warning
+  return r;
+}
+
+int getentropy2(void) {
+  char buf[1024] = {0};
+
+  int r = getentropy(buf, sizeof(buf)); // expected-warning{{must be smaller than or equal to 256}}
+  return r;
+}
+
+int getentropy3(void) {
+  char buf[256] = {0};
+
+  int r = getentropy(buf, 0); // no-wwarning
----------------
NagyDonat wrote:

```suggestion
  int r = getentropy(buf, 0); // no-warning
```
Just a typo. (By the way, "no-warning" is just a comment, it's not significant for the test engine. The tests will fail if when any unexpected warning appears, but it's customary to write no-warning after the statements that are the "central" parts of a testcase but should not produce a warning.)

https://github.com/llvm/llvm-project/pull/83675


More information about the cfe-commits mailing list