...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdlib.h>
struct gadget {
int i;
double d;
char *p;
};
struct widget {
char *q;
int j;
double e;
};
struct gadget *gp;
struct widget *wp;
gp = (struct gadget *)malloc(sizeof (struct gadget));
/* ... */
wp = (struct widget *)realloc(gp, sizeof(struct widget));
if (wp->j == 12) {
/* ... */
} |
Compliant Solution
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdlib.h> #include <string.h> struct gadget { int i; double d; char *p; }; struct widget { char *q; int j; double e; }; struct gadget *gp; struct widget *wp; gp = (struct gadget *)malloc(sizeof (struct gadget)); /* ... */ wp = (struct widget *)realloc(gp, sizeof(struct widget)); memset(wp, 0, sizeof(struct widget)); /* ... */ if (wp->j == 12) { /* ... */ } |
Risk Assessment
...