BitVecReplaceAll
Description
Replace all occurrences of old pattern with new pattern.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to modify |
old_pattern |
in | Pattern to find and replace |
new_pattern |
in | Pattern to replace with |
Usage example (from documentation)
u64 count = BitVecReplaceAll(&flags, &old_pat, &new_pat);Success
Number of replacements made; bv reflects all rewrites.
Failure
Returns 0 when no match was found; aborts the walk and leaves bv in its pre-call state on allocator OOM.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1817:
}
u64 BitVecReplaceAll(BitVec *bv, BitVec *old_pattern, BitVec *new_pattern) {
ValidateBitVec(bv);
ValidateBitVec(old_pattern); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReplaceAll(uninitialized, old, new) - should fatal\n");
BitVec bad = {0}; // magic mismatch -> ValidateBitVec aborts
push_bits(&new_pattern, "0");
BitVecReplaceAll(&bad, &old_pattern, &new_pattern); // real: LOG_FATAL
BitVecDeinit(&old_pattern); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReplaceAll(empty, NULL, new) - should fatal\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
push_bits(&new_pattern, "0");
BitVecReplaceAll(&source, NULL, &new_pattern); // real: LOG_FATAL
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReplaceAll(empty, old, NULL) - should fatal\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
push_bits(&old_pattern, "1");
BitVecReplaceAll(&source, &old_pattern, NULL); // real: LOG_FATAL
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReplaceAll basic functionality\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&new_pattern, true);
u64 replacements = BitVecReplaceAll(&source, &old_pattern, &new_pattern);
result = result && (replacements == 3); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReplaceAll found-flag init\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); push_bits(&new_pattern, "0");
u64 replacements = BitVecReplaceAll(&source, &old_pattern, &new_pattern);
result = result && (replacements == 0);
result = result && (BitVecLen(&source) == 4); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReplaceAll forward-scan direction\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); push_bits(&new_pattern, "01");
u64 replacements = BitVecReplaceAll(&source, &old_pattern, &new_pattern);
result = result && (replacements == 1);
result = result && (BitVecLen(&source) == 4); // 5 - 3 + 2
BitVecPush(&neww, true);
u64 n = BitVecReplaceAll(&source, &old, &neww);
result = result && (n == 0);
result = result && (BitVecLen(&source) == 4); BitVecPush(&neww, true);
u64 n = BitVecReplaceAll(&source, &old, &neww);
result = result && (n == 3);
result = result && (BitVecLen(&source) == 6);
Last updated on