MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / CanMakeSizeT

Function CanMakeSizeT

include/bmpread/bmpread.c:84–98  ·  view source on GitHub ↗

Returns nonzero if the uint32_t can be converted to a size_t without losing * data, which is always the case on 32-bit systems and higher, or 0 if such a * conversion would lose data, as could happen on 16-bit systems. */

Source from the content-addressed store, hash-verified

82 * conversion would lose data, as could happen on 16-bit systems.
83 */
84static int CanMakeSizeT(uint32_t x)
85{
86 /* The preprocessor guard is there to prevent a warning about the condition
87 * inside being true by definition on systems where size_t is at least 32
88 * bits. I'm relying on C's integer promotion rules to make this all safe.
89 * I *think* it works as intended here (either way, typecasts don't really
90 * help clarify things, so I've gone without).
91 */
92#if UINT32_MAX > SIZE_MAX
93 if(x > SIZE_MAX) return 0;
94#endif
95
96 (void)x; /* Sometimes unused; this prevents a pedantic warning. */
97 return 1;
98}
99
100/* Returns nonzero if the uint32_t can be converted to a long without losing
101 * data, or 0 if the conversion would lose data.

Callers 1

ValidateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected