...
Code Block | ||
---|---|---|
| ||
void f1 (size_t nchars, size_t val) { char *p = (char *)malloc(nchars); const size_t n = val; if (nchars -< n < 0) { Â Â Â Â /* Handle Error */ } else { memset(p, 0, n); } } |
...
Code Block | ||
---|---|---|
| ||
void f3(int *a) { float b = 3.14; const size_t n = sizeof(*b); void *p = a; void *q = &b; memcpy(p, q, n); /* More program code */ } |
Note: A possibility of this code being safe would be on architectures where sizeof (int) is equal to sizeof (float).
Compliant Solution // (need to work on this)
...
API00-C. Functions should validate their parameters\
WG14 Document: N1579 - Rule 5.34 Forming Invalid pointers by library functions.
...