...
Code Block | ||
---|---|---|
| ||
/* ... */ list = malloc(sizeof(int) * s); if (list == NULL) { /* Handle Allocation Error */ } /* Continue Processing list */ /* ... */ |
Compliant Code Example
Wiki Markup |
---|
To ensure that zero is never passed as a size argument to {{malloc()}}, a check must be made on {{s}} to ensure it is not zero. Note that this solution checks for numeric overflow \[[INT32-C. Ensure that integer operations do not result in an overflow]\]. |
Code Block | ||
---|---|---|
| ||
if (s == 0) { /* Handle ...Error */ } if (sizeof(sint) <= 0> SIZE_MAX/s) { /* Handlehandle Erroroverflow */ } list = malloc(sizeof(int) * s); if (list == NULL) { /* Handle Allocation Error */ } /* Continue Processing list */ /* ... */ |
...