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

Function ParseBitfield

include/bmpread/bmpread.c:332–354  ·  view source on GitHub ↗

Turns a single mask component into a bitfield. Returns 0 if the bitmask was * invalid, or nonzero if it's ok. Span of 0 means the bitmask was absent. */

Source from the content-addressed store, hash-verified

330 * invalid, or nonzero if it's ok. Span of 0 means the bitmask was absent.
331 */
332static int ParseBitfield(bitfield * field, uint32_t mask)
333{
334 uint32_t bit;
335 for(bit = 0; bit < 32 && !(mask & (UINT32_C(1) << bit)); bit++)
336 ;
337
338 if(bit >= 32)
339 {
340 /* Absent bitmasks are valid. */
341 field->start = field->span = 0;
342 return 1;
343 }
344
345 field->start = bit;
346 for(; bit < 32 && (mask & (UINT32_C(1) << bit)); bit++)
347 ;
348 field->span = bit - field->start;
349
350 /* If there are more set bits, there was a gap, which is invalid. */
351 if(bit < 32 && (mask & ~((UINT32_C(1) << bit) - 1))) return 0;
352
353 return 1;
354}
355
356/* A single color entry in the palette, in file order (BGR + one unused byte).
357 */

Callers 1

ValidateBitfieldsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected