...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> #include <inttypes.h> mytypedef_t x; /* ... */ printf("%ju", (uintmax_t) x); |
Compliant Solution (Microsoft printf()
)
Visual Studio 2012 and earlier versions do not support the standard j
length modifier or have a non-standard analogue. Consequently, you'll need to hard code the knowledge that intmax_t
is int64_t
and uintmax_t
is
for Microsoft Visual Studio versions.uint64_t
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h>
#include <inttypes.h>
mytypedef_t x;
/* ... */
#ifdef _MSC_VER
printf("%llu", (uintmax_t) x);
#else
printf("%ju", (uintmax_t) x);
#endif |
Microsoft has submitted a feature request to add support for the j
length modifier to a future release of Microsoft Visual Studio.
Noncompliant Code Example (scanf()
)
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> #include <inttypes.h> mytypedef_t x; uintmax_t temp; /* ... */ if (scanf("%ju", &temp) != 1) { /* handle error */ } if (temp > MYTYPEDEF_MAX) { /* handle error */ } else { x = temp; } |
Compliant Solution (Microsoft scanf()
)
Visual Studio 2012 and earlier versions do not support the standard j
length modifier or have a non-standard analogue. Consequently, you'll need to hard code the knowledge that intmax_t
is int64_t
and uintmax_t
is
for Microsoft Visual Studio versions.uint64_t
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> #include <inttypes.h> mytypedef_t x; uintmax_t temp; /* ... */ #ifdef _MSC_VER # define UINTMAX_CS "%llu" #else # define UINTMAX_CS "%ju" #endif if (scanf(UINTMAX_CS, &temp) != 1) { /* handle error */ } if (temp > MYTYPEDEF_MAX) { /* handle error */ } else { x = temp; } |
Microsoft has submitted a feature request to add support for the j
length modifier to a future release of Microsoft Visual Studio.
Risk Assessment
Failure to use an appropriate conversion specifier when inputting or outputting programmer-defined integer types can result in buffer overflow and lost or misinterpreted data.
...