Skip to content
BitVecEndsWith

BitVecEndsWith

Description

Check if bitvector ends with the given bit pattern.

Parameters

Name Direction Description
bv in Bitvector to check
suffix in Pattern to match at the end

Usage example (from documentation)

  bool ends = BitVecEndsWith(&flags, &pattern);

Success

true if bitvector ends with the pattern

Failure

false if the suffix is longer than bv or any bit differs.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool BitVecEndsWith(BitVec *bv, BitVec *suffix) {
        ValidateBitVec(bv);
        ValidateBitVec(suffix);
    
        VecForeachPtrIdx(patterns, pattern, i) {
            if (BitVecEndsWith(bv, pattern)) {
                return i;
            }
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecEndsWith basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&suffix, true);
    
        result = result && BitVecEndsWith(&source, &suffix);
    
        // Test non-matching suffix: 110
        BitVecPush(&suffix, false);
    
        result = result && !BitVecEndsWith(&source, &suffix);
    
        BitVecDeinit(&source);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecEndsWith edge cases\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test empty suffix (should always match)
        BitVecPush(&source, true);
        result = result && BitVecEndsWith(&source, &suffix);
    
        // Test suffix longer than source
        BitVecPush(&suffix, true);
        BitVecPush(&suffix, false);
        result = result && !BitVecEndsWith(&source, &suffix);
    
        BitVecDeinit(&source);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecEndsWith(NULL, suffix) - should fatal\n");
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&suffix, true);
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&suffix, true);
        BitVecEndsWith(NULL, &suffix);
        BitVecDeinit(&suffix);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecEndsWith(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecEndsWith(&source, NULL);
        BitVecDeinit(&source);
        DefaultAllocatorDeinit(&alloc);
Last updated on