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

Function ValidateBitfields

include/bmpread/bmpread.c:428–458  ·  view source on GitHub ↗

A sub-function to Validate() that handles the bitfields. Returns 0 on * invalid bitfields or nonzero on success. Note that we don't treat odd * bitmasks such as R8G8 or A1G1B1 as invalid, even though they may not load in * most other loaders. */

Source from the content-addressed store, hash-verified

426 * most other loaders.
427 */
428static int ValidateBitfields(read_context * p_ctx)
429{
430 bitfield * bf = p_ctx->bitfields;
431
432 uint32_t total_mask = 0;
433 bitfield total_field;
434
435 int i;
436
437 if(p_ctx->info.compression != COMPRESSION_BITFIELDS)
438 return 1;
439
440 for(i = 0; i < 4; i++)
441 {
442 /* No overlapping masks. */
443 if(total_mask & p_ctx->info.masks[i]) return 0;
444 total_mask |= p_ctx->info.masks[i];
445
446 if(!ParseBitfield(&bf[i], p_ctx->info.masks[i])) return 0;
447
448 /* Make sure we fit in our bit size. */
449 if(bf[i].start + bf[i].span > p_ctx->info.bits) return 0;
450 }
451
452 if(!total_mask) return 0;
453
454 /* Check for contiguous-ity between fields, too. */
455 if(!ParseBitfield(&total_field, total_mask)) return 0;
456
457 return 1;
458}
459
460/* A sub-function to Validate() that handles the palette. Returns 0 on EOF or
461 * invalid palette, or nonzero on success.

Callers 1

ValidateFunction · 0.85

Calls 1

ParseBitfieldFunction · 0.85

Tested by

no test coverage detected