IntFromBytesLE
Description
Create an integer from little-endian bytes.
Parameters
| Name | Direction | Description |
|---|---|---|
bytes |
in | Source byte buffer holding the magnitude in little-endian order (least significant byte first). May be NULL when len == 0. |
len |
in | Number of bytes to read from bytes. |
alloc |
in | Allocator to bind to the returned integer. |
Success
Returns a normalised Int holding the unsigned magnitude packed in bytes. bytes is not modified.
Failure
Returns a zero-initialised Int bound to alloc when the underlying bit-vector allocation fails. The caller cannot distinguish that from a true zero result. LOG_FATAL when bytes is NULL and len != 0.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Convert.c:118:
u8 bytes[] = {0x34, 0x12, 0xEF, 0xCD};
u8 out[4] = {0};
Int value = IntFromBytesLE(bytes, sizeof(bytes), ALLOCATOR_OF(&alloc));
u64 written = IntToBytesLE(&value, out, sizeof(out));
Str text = IntToHexStr(&value);- In
Convert.c:572:
bool test_int_from_bytes_le_null(void) {
WriteFmt("Testing IntFromBytesLE NULL handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:576:
DefaultAllocator alloc = DefaultAllocatorInit();
IntFromBytesLE(NULL, 1, ALLOCATOR_OF(&alloc));
DefaultAllocatorDeinit(&alloc);
return false;- In
Convert.c:1410:
// Real code returns a zero Int cleanly; the mutant crashes -> distinguishable.
bool test_m27_from_bytes_le_null_zero_no_abort(void) {
WriteFmt("Testing IntFromBytesLE(NULL, 0) yields zero without aborting\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:1414:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromBytesLE(NULL, 0, ALLOCATOR_OF(&alloc));
bool result = IntIsZero(&value);- In
Convert.c:1431:
// Real code: value 5, IntBitLength == 3; mutant: IntBitLength == 16.
bool test_m27_from_bytes_le_trailing_zero_normalized(void) {
WriteFmt("Testing IntFromBytesLE normalizes trailing zero bytes\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:1436:
u8 bytes[] = {0x05, 0x00};
Int value = IntFromBytesLE(bytes, sizeof(bytes), ALLOCATOR_OF(&alloc));
bool result = (IntToU64(&value) == 5);
Last updated on