...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdint.h>
#include <stdlib.h>
void function(size_t len) {
long *p;
if (len == 0 || len > SIZE_MAX / sizeof(long)) {
/* Handle overflow */
}
p = (long *)malloc(len * sizeof(int));
if (p == NULL) {
/* Handle error */
}
free(p);
}
|
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdint.h> #include <stdlib.h> void function(size_t len) { long *p; if (len == 0 || len > SIZE_MAX / sizeof(long)) { /* Handle overflow */ } p = (long *)malloc(len * sizeof(long)); if (p == NULL) { /* Handle error */ } free(p); } |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdint.h>
#include <stdlib.h>
void function(size_t len) {
long *p;
if (len == 0 || len > SIZE_MAX / sizeof(*p)) {
/* Handle overflow */
}
p = (long *)malloc(len * sizeof(*p));
if (p == NULL) {
/* Handle error */
}
free(p);
}
|
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdlib.h>
#include <time.h>
struct tm *make_tm(int year, int mon, int day, int hour,
int min, int sec) {
struct tm *tmb;
tmb = (struct tm *)malloc(sizeof(tmb));
if (tmb == NULL) {
return NULL;
}
tmb->tm_sec = sec;
tmb->tm_min = min;
tmb->tm_hour = hour;
tmb->tm_mday = day;
tmb->tm_mon = mon;
tmb->tm_year = year;
return tmb;
} |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdlib.h>
#include <time.h>
struct tm *make_tm(int year, int mon, int day, int hour,
int min, int sec) {
struct tm *tmb;
tmb = (struct tm *)malloc(sizeof(*tmb));
if (tmb == NULL) {
return NULL;
}
tmb->tm_sec = sec;
tmb->tm_min = min;
tmb->tm_hour = hour;
tmb->tm_mday = day;
tmb->tm_mon = mon;
tmb->tm_year = year;
return tmb;
} |
...