Versions Compared

Key

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

...

Code Block
bgColor#ccccff
langc
int (*log_fn)(const char *, ...) = EncodePointer(printf);
/* ... */
DecodePointer(log_fn)("foo");

Compliant Solution (C1X)

Two similar functions are under consideration for the C1X major revision to the C Standard.

C1X defines encode_pointer() to have the following behavior:

The encode_pointer function shall perform a transformation on the pf argument, such that the decode_pointer function shall reverse that transformation. Thus, for any pointer to function pfun,

Code Block
decode_pointer(encode_pointer( (void(*)()) pfun )

when converted to the type of pfun, shall equal pfun.

Code Block
bgColor#ccccff
langc
int (*log_fn)(const char *, ...) = encode_pointer(printf);
/* ... */
decode_pointer(log_fn)("foo");

Risk Assessment

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

MSC16-C

high

unlikely

low

P9

L2

...