Versions Compared

Key

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

...

Code Block
bgColor#ccccff
enum month { Jan, Feb, ... };
type enum month month;

typedef enum date date;
struct date {
  unsigned char dd;
  month mm;
  unsigned yy;
};

typedef struct string string;
struct string {
  size_t length;
  char text[];
};

date *d, *week, *fortnight;
string *name;

d = MALLOC(date);
week = MALLOC_ARRAY(7, date);
name = MALLOC_FLEX(string, 16, char);
fortnight = CALLOC(14, date);

The multiplication operation If one or more of the operands to the multiplication operations used in many of these macro must be checked for overflow if one or more of the operands definitions can be influenced by untrusted data, these operands should be checked for overflow before invoking the macro (see INT32-C. Ensure that integer operations do not result in an overflow for more information).

Risk Assessment

Failing to cast the result of a memory allocation function call into a pointer to the allocated type can result in inadvertent pointer conversions. Code that follows this recommendation will compile and execute equally well in C++.

...