Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
typedef struct s {
    int i;
    double d;
} mystruct;

size_t size = sizeof(mystruct);
printf("Size of struct: %d bytes\n", size);

...

Code Block
bgColor#FFcccc
/* assuming 32-bit pointer, 32-bit integer */
size_t i;
int ** triarray = calloc(100, 4);

for (i = 0; i < 100; i++) {
    triarray[i] = calloc(i, 4);
}

...

Code Block
bgColor#ccccff
size_t i;
int **triarray = calloc(100, sizeof(int *));

if (!triarray) {
    { /* perform cleanup, return error */ 
}

for (i = 0; i < 100; i++) {
    triarray[i] = calloc(i, sizeof(int));
    if (!triarray[i]) {
        { /* perform cleanup, return error */ }
    }
}

Risk Assessment

If non-compliant code is ported to a different platform, it could introduce a heap or stack overflow vulnerability.

...