...
Noncompliant Code Example (Two Pointers + One Integer)
This In this noncompliant code example is noncompliant because , the value of n
is incorrectly computed, allowing a possible write read past the end of the object referenced by p
q
:
Code Block | ||
---|---|---|
| ||
#include <string.h> void f4() { char p[40],; const char *q) { const = "Too short"; size_t n = sizeof(p); memcpy(p, q, n); } |
...
Compliant Solution (Two Pointers + One Integer)
...
Code Block | ||
---|---|---|
| ||
#include <string.h> void f4() { char p[40],; const char *q, = "Too short"; size_t n = sizeof(p) < strlen(q) { + 1 ? sizeof(p) : strlen(q) + 1; memcpy(p, q, n); } |
One Pointer + Two Integers
...