Skip to content

LOG_FATAL

LOG_FATAL

Description

Writes a fatal log message and aborts the program.

…[in] : Format string and arguments following printf-style syntax.

Success

Message logged and program aborted via abort()

Failure

Logging may fail silently, but abort() will still execute

Usage example (Cross-references)

Usage examples (Cross-references)
    i32 MemCompare(const void *p1, const void *p2, size n) {
        if (!p1 || !p2) {
            LOG_FATAL("Invalid arguments");
        }
    void *MemCopy(void *dst, const void *src, size n) {
        if (!dst || !src) {
            LOG_FATAL("Invalid arguments");
        }
    void *MemMove(void *dst, const void *src, size n) {
        if (!dst || !src) {
            LOG_FATAL("Invalid arguments");
        }
    void *MemSet(void *dst, i32 val, size n) {
        if (!dst) {
            LOG_FATAL("Invalid arguments");
        }
    size ZstrLen(const char *str) {
        if (!str) {
            LOG_FATAL("Invalid arguments");
        }
    i32 ZstrCompare(const char *s1, const char *s2) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
        }
    i32 ZstrCompareN(const char *s1, const char *s2, size n) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
        }
    char *ZstrDupN(const char *src, size n) {
        if (!src) {
            LOG_FATAL("Invalid arguments");
        }
    bool ZstrInitClone(const char **dst, const char **src) {
        if (!dst || !src || !*src) {
            LOG_FATAL("Invalid arguments.");
        }
    void ZstrDeinit(const char **zs) {
        if (!zs) {
            LOG_FATAL("Invalid arguments");
        }
    char *ZstrFindSubstring(const char *haystack, const char *needle) {
        if (!haystack || !needle) {
            LOG_FATAL("Invalid arguments");
        }
    char *ZstrFindSubstringN(const char *haystack, const char *needle, size needle_len) {
        if (!haystack || !needle) {
            LOG_FATAL("Invalid arguments");
        }
    static bool ParseFormatSpec(const char *spec, u32 len, FmtInfo *fi) {
        if (!spec || !fi) {
            LOG_FATAL("Invalid arguments to ParseFormatSpec");
            return false;
        }
    bool StrWriteFmtInternal(Str *o, const char *fmt, TypeSpecificIO *args, u64 argc) {
        if (!o || !fmt) {
            LOG_FATAL("Invalid arguments");
            return false;
        }
                    }
    #else
                    LOG_FATAL("Invalid writer or data pointer");
    #endif
                }
    const char *StrReadFmtInternal(const char *input, const char *fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!input || !fmtstr) {
            LOG_FATAL("Invalid arguments");
        }
    void FReadFmtInternal(FILE *file, const char *fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!file || !fmtstr) {
            LOG_FATAL("Invalid arguments");
        }
    static inline void write_int_as_chars(Str *o, FormatFlags flags, u64 value, size num_bytes) {
        if (!o || !num_bytes || num_bytes > 8) {
            LOG_FATAL("Invalid arguments to write_int_as_chars");
        }
    static inline void write_char_internal(Str *o, FormatFlags flags, const char *vs, size len) {
        if (!o || !vs || !len) {
            LOG_FATAL("Invalid arguments");
        }
    
        if (!out) {
            LOG_FATAL("Invalid arguments");
        }
    
        if (!input) {
            LOG_FATAL("input is NULL");
        }
    static inline const char *read_chars_internal(const char *i, u8 *buffer, size buffer_size, FmtInfo *fmt_info) {
        if (!i || !buffer || !buffer_size) {
            LOG_FATAL("Invalid arguments to read_chars_internal");
        }
    void _write_Str(Str *o, FmtInfo *fmt_info, Str *s) {
        if (!o || !s || !fmt_info) {
            LOG_FATAL("Invalid arguments");
        }
    void _write_Zstr(Str *o, FmtInfo *fmt_info, const char **s) {
        if (!o || !s || !*s || !fmt_info) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_u64(Str *o, FmtInfo *fmt_info, u64 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_u32(Str *o, FmtInfo *fmt_info, u32 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_u16(Str *o, FmtInfo *fmt_info, u16 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_u8(Str *o, FmtInfo *fmt_info, u8 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_i64(Str *o, FmtInfo *fmt_info, i64 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_i32(Str *o, FmtInfo *fmt_info, i32 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_i16(Str *o, FmtInfo *fmt_info, i16 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_i8(Str *o, FmtInfo *fmt_info, i8 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_f64(Str *o, FmtInfo *fmt_info, f64 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_f32(Str *o, FmtInfo *fmt_info, f32 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    
        if (!o || !fmt_info || !value) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    
        if (FloatFmtUsesUnsupportedFlags(fmt_info)) {
            LOG_FATAL("Float only supports decimal and scientific formatting");
        }
    const char *_read_Str(const char *i, FmtInfo *fmt_info, Str *s) {
        if (!i || !s)
            LOG_FATAL("Invalid arguments");
    
        ValidateStr(s);
    const char *_read_f64(const char *i, FmtInfo *fmt_info, f64 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_u8(const char *i, FmtInfo *fmt_info, u8 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Skip whitespace
    const char *_read_u16(const char *i, FmtInfo *fmt_info, u16 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_u32(const char *i, FmtInfo *fmt_info, u32 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_u64(const char *i, FmtInfo *fmt_info, u64 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_i8(const char *i, FmtInfo *fmt_info, i8 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_i16(const char *i, FmtInfo *fmt_info, i16 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_i32(const char *i, FmtInfo *fmt_info, i32 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    const char *_read_i64(const char *i, FmtInfo *fmt_info, i64 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
        (void)fmt_info; // Unused parameter
        if (!i || !out)
            LOG_FATAL("Invalid arguments");
    
        // For string types, :c has no effect - work like regular string reading
    void _write_BitVec(Str *o, FmtInfo *fmt_info, BitVec *bv) {
        if (!o || !fmt_info || !bv) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    void _write_Int(Str *o, FmtInfo *fmt_info, Int *value) {
        if (!o || !fmt_info || !value) {
            LOG_FATAL("Invalid arguments");
            return;
        }
    
            if (!buffer) {
                LOG_FATAL("Failed to allocate buffer for Int character formatting");
            }
        (void)fmt_info;
        (void)s;
        LOG_FATAL("Attempt to write unsupported type");
    }
        (void)fmt_info; // Unused parameter
        if (!i || !bv) {
            LOG_FATAL("Invalid arguments");
            return i;
        }
    const char *_read_Int(const char *i, FmtInfo *fmt_info, Int *value) {
        if (!i || !value) {
            LOG_FATAL("Invalid arguments");
        }
    
        if (!i || !value) {
            LOG_FATAL("Invalid arguments");
        }
        (void)fmt_info; // Unused parameter
        (void)s;
        LOG_FATAL("Attempt to read unsupported type.");
        return i;
    }
    const char *_read_f32(const char *i, FmtInfo *fmt_info, f32 *v) {
        if (!i || !v)
            LOG_FATAL("Invalid arguments");
    
        // Handle character format specifier
    static void _write_r8(Str *o, FmtInfo *fmt_info, u8 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
        }
    static void _write_r16(Str *o, FmtInfo *fmt_info, u16 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
        }
            case ENDIAN_NATIVE :
            default : {
                LOG_FATAL("Invalid endianness provided. Unexpected code reached.");
            }
        }
    static void _write_r32(Str *o, FmtInfo *fmt_info, u32 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
        }
            case ENDIAN_NATIVE :
            default : {
                LOG_FATAL("Invalid endianness provided. Unexpected code reached.");
            }
        }
    static void _write_r64(Str *o, FmtInfo *fmt_info, u64 *v) {
        if (!o || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
        }
            case ENDIAN_NATIVE :
            default : {
                LOG_FATAL("Invalid endianness provided. Unexpected code reached.");
            }
        }
    static const char *_read_r8(const char *i, FmtInfo *fmt_info, u8 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
        }
    static const char *_read_r16(const char *i, FmtInfo *fmt_info, u16 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments to _read_r16");
        }
            case ENDIAN_NATIVE :
            default :
                LOG_FATAL("Invalid endianness provided. Unexpected code reached in _read_r16.");
        }
    static const char *_read_r32(const char *i, FmtInfo *fmt_info, u32 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments to _read_r32");
        }
            case ENDIAN_NATIVE :
            default :
                LOG_FATAL("Invalid endianness provided. Unexpected code reached in _read_r32.");
        }
    static const char *_read_r64(const char *i, FmtInfo *fmt_info, u64 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments to _read_r64");
        }
            case ENDIAN_NATIVE :
            default :
                LOG_FATAL("Invalid endianness provided. Unexpected code reached in _read_r64.");
        }
    
        if (!v->alignment) {
            LOG_FATAL("Invalid alignment. Did you initialize before use? Aborting...");
        }
    
        if (idx > vec->length) {
            LOG_FATAL("vector index out of bounds, insertion at index greater than length");
        }
    
        if (idx > vec->length) {
            LOG_FATAL("vector index out of bounds, insertion at index greater than length");
        }
    
        if (start + count > vec->length) {
            LOG_FATAL("vector range out of bounds.");
        }
    
        if (start + count > vec->length) {
            LOG_FATAL("vector range out of bounds.");
        }
    
        if (vec_aligned_size(vec, item_size) != item_size) {
            LOG_FATAL(
                "QSort not implemented for vectors wherein the size of items don't "
                "match their aligned size."
    
        if (idx1 >= vec->length || idx2 >= vec->length) {
            LOG_FATAL("vector index out of bounds.");
        }
    void validate_vec(const GenericVec *v) {
        if (!(v)) {
            LOG_FATAL("NULL vec object pointer.");
        }
        if ((v)->__magic != MISRA_VEC_MAGIC) {
        }
        if ((v)->__magic != MISRA_VEC_MAGIC) {
            LOG_FATAL("Invalid vec object. Either uninitialized or corrupted!");
        }
        if (!(v)->alignment || (v)->length > (v)->capacity) {
        }
        if (!(v)->alignment || (v)->length > (v)->capacity) {
            LOG_FATAL("Invalid vec object.");
        }
        // if memory is invalid, system will segfault here
    static i64 float_add_i64_checked(i64 a, i64 b) {
        if ((b > 0 && a > INT64_MAX - b) || (b < 0 && a < INT64_MIN - b)) {
            LOG_FATAL("Float exponent overflow");
        }
    static i64 float_sub_i64_checked(i64 a, i64 b) {
        if ((b > 0 && a < INT64_MIN + b) || (b < 0 && a > INT64_MAX + b)) {
            LOG_FATAL("Float exponent overflow");
        }
    
        if (len < 0 || len >= (int)sizeof(text)) {
            LOG_FATAL("Failed to convert f32 to Float");
        }
    
        if (len < 0 || len >= (int)sizeof(text)) {
            LOG_FATAL("Failed to convert f64 to Float");
        }
        }
        if (target_exponent > value->exponent) {
            LOG_FATAL("target exponent must not exceed current exponent");
        }
        if (target_exponent == value->exponent) {
    
        if (!text) {
            LOG_FATAL("text is NULL");
        }
            if (ch == '.') {
                if (saw_decimal) {
                    LOG_FATAL("Invalid Float format");
                }
                pos++;
                if (text[pos] == '\0') {
                    LOG_FATAL("Invalid Float exponent");
                }
                parsed = strtoll(text + pos, &endptr, 10);
                if (errno == ERANGE || endptr == text + pos || *endptr != '\0') {
                    LOG_FATAL("Invalid Float exponent");
                }
            }
    
            LOG_FATAL("Invalid Float format");
        }
    
        if (!saw_digit) {
            LOG_FATAL("Invalid Float format");
        }
    
        if (FloatIsZero(b)) {
            LOG_FATAL("Division by zero");
        }
        if (FloatIsZero(a)) {
    void insert_into_list(GenericList *list, void *item_data, u64 item_size, u64 idx) {
        if (!list || !item_size || !item_data) {
            LOG_FATAL("invalid arguments.");
        }
            }
        } else {
            LOG_FATAL("list index out of range.");
        }
    void remove_range_list(GenericList *list, void *removed_data, u64 item_size, u64 start, u64 count) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    
        if (start + count > list->length) {
            LOG_FATAL("List range out of bounds.");
        }
    void qsort_list(GenericList *list, u64 item_size, GenericCompare comp) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    void swap_list(GenericList *list, u64 item_size, u64 idx1, u64 idx2) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
        GenericListNode *n1 = node_at_list(list, item_size, idx1);
        if (!n1) {
            LOG_FATAL("failed to get node at specified index");
        }
        GenericListNode *n2 = node_at_list(list, item_size, idx2);
        if (!n2) {
            LOG_FATAL("failed to get node at specified index");
        }
    void reverse_list(GenericList *list, u64 item_size) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    void push_arr_list(GenericList *list, u64 item_size, void *arr, u64 count) {
        if (!list || !arr || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    
            if (!new_tail) {
                LOG_FATAL("Failed to allocate memory for new node");
            }
            if (!new_tail->data) {
                free(new_tail);
                LOG_FATAL("Failed to allocate memory for node data");
            }
    void merge_list(GenericList *list1, u64 item_size, GenericList *list2) {
        if (!list1 || !item_size || !list2) {
            LOG_FATAL("invalid arguments.");
        }
    void clear_list(GenericList *list, u64 item_size) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    GenericListNode *node_at_list(GenericList *list, u64 item_size, u64 idx) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    
        if (idx >= list->length) {
            LOG_FATAL("list index out of range.");
        }
    void *item_ptr_at_list(GenericList *list, u64 item_size, u64 idx) {
        if (!list || !item_size) {
            LOG_FATAL("invalid arguments.");
        }
    
        if (idx >= list->length) {
            LOG_FATAL("list index out of bounds.");
        }
    void validate_list(const GenericList *l) {
        if (!(l)) {
            LOG_FATAL("List pointer is NULL.");
        }
        if ((l)->__magic != MISRA_LIST_MAGIC) {
        }
        if ((l)->__magic != MISRA_LIST_MAGIC) {
            LOG_FATAL("Invalid list. Either not initialized or corrupted!");
        }
        if ((l)->length > 0) {
        if ((l)->length > 0) {
            if (!(l)->head) {
                LOG_FATAL("Non-empty list has NULL head.");
            }
            if (!(l)->tail) {
            }
            if (!(l)->tail) {
                LOG_FATAL("Non-empty list has NULL tail.");
            }
        }
    GenericListNode *get_node_relative_to_list_node(GenericListNode *node, i64 ridx) {
        if (!node) {
            LOG_FATAL("Invalid arguments");
        }
    GenericListNode *get_node_random_access(GenericList *list, GenericListNode *node, u64 nidx, i64 ridx) {
        if (!list || !node) {
            LOG_FATAL("Invalid arguments");
        }
    
        if (nidx >= list->length) {
            LOG_FATAL("Node index exceeds list bounds");
        }
    
        if ((ridx < 0 && (u64)(-ridx) > nidx) || (ridx > 0 && nidx + (u64)ridx >= list->length)) {
            LOG_FATAL("Relative node index outside of list bounds");
        }
    static void int_validate_radix(u8 radix) {
        if (radix < 2 || radix > 36) {
            LOG_FATAL("radix must be between 2 and 36");
        }
    }
            digit = int_radix_digit(digits[i]);
            if (digit < 0 || digit >= radix) {
                LOG_FATAL("Invalid digit for radix in Int conversion");
            }
    
        if (!digits) {
            LOG_FATAL("digits is NULL");
        }
    
            if (digit < 0 || digit >= radix) {
                LOG_FATAL("Invalid digit for radix in Int conversion");
            }
    
        if (IntIsZero(value)) {
            LOG_FATAL("log2 undefined for zero");
        }
    Int MISRA_PRIV_IntFromI64(i64 value) {
        if (value < 0) {
            LOG_FATAL("Int cannot represent negative values");
        }
    
        if (!IntFitsU64(value)) {
            LOG_FATAL("Int value exceeds u64 range");
        }
    Int IntFromBytesLE(const u8 *bytes, u64 len) {
        if (!bytes && len != 0) {
            LOG_FATAL("bytes is NULL");
        }
    
        if (!bytes) {
            LOG_FATAL("bytes is NULL");
        }
        if (max_len == 0) {
        }
        if (max_len == 0) {
            LOG_FATAL("max_len is 0");
        }
    Int IntFromBytesBE(const u8 *bytes, u64 len) {
        if (!bytes && len != 0) {
            LOG_FATAL("bytes is NULL");
        }
    
        if (!bytes) {
            LOG_FATAL("bytes is NULL");
        }
        if (max_len == 0) {
        }
        if (max_len == 0) {
            LOG_FATAL("max_len is 0");
        }
    Int IntFromStr(const char *decimal) {
        if (!decimal) {
            LOG_FATAL("decimal is NULL");
        }
    
        if (!digits) {
            LOG_FATAL("digits is NULL");
        }
        if (digits[0] == '+') {
    Int IntFromBinary(const char *binary) {
        if (!binary) {
            LOG_FATAL("binary is NULL");
        }
    Int IntFromOctStr(const char *octal) {
        if (!octal) {
            LOG_FATAL("octal is NULL");
        }
    Int IntFromHexStr(const char *hex) {
        if (!hex) {
            LOG_FATAL("hex is NULL");
        }
    
        if (!MISRA_PRIV_IntSubU64(result, value, magnitude)) {
            LOG_FATAL("IntAdd would produce a negative result");
        }
    }
    void MISRA_PRIV_IntMulI64(Int *result, Int *value, i64 factor) {
        if (factor < 0) {
            LOG_FATAL("Int cannot be multiplied by a negative scalar");
        }
    
        if (!IntFitsU64(exponent)) {
            LOG_FATAL("Int exponent exceeds u64 range");
        }
    void MISRA_PRIV_IntPowI64(Int *result, Int *base, i64 exponent) {
        if (exponent < 0) {
            LOG_FATAL("Int exponent cannot be negative");
        }
    
        if (quotient == remainder) {
            LOG_FATAL("quotient and remainder must be different objects");
        }
        if (IntIsZero(divisor)) {
        }
        if (IntIsZero(divisor)) {
            LOG_FATAL("Division by zero");
        }
    
        if (IntIsZero(divisor)) {
            LOG_FATAL("Division by zero");
        }
    
        if (divisor == 0) {
            LOG_FATAL("Division by zero");
        }
    
        if (modulus == 0) {
            LOG_FATAL("modulus is zero");
        }
    
        if (root == remainder) {
            LOG_FATAL("root and remainder must be different objects");
        }
        if (degree == 0) {
        }
        if (degree == 0) {
            LOG_FATAL("root degree is zero");
        }
    
        if (IntIsZero(n) || IntIsEven(n)) {
            LOG_FATAL("n must be non-zero and odd");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    void MISRA_PRIV_IntPowI64Mod(Int *result, Int *base, i64 exponent, Int *modulus) {
        if (exponent < 0) {
            LOG_FATAL("Int exponent cannot be negative");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (IntIsZero(modulus)) {
            LOG_FATAL("modulus is zero");
        }
    
        if (!new_data) {
            LOG_FATAL("Failed to allocate memory for bitvec");
            return;
        }
        ValidateBitVec(bitvec);
        if (idx >= bitvec->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bitvec->length);
        }
        u64 byte_idx   = BIT_INDEX(idx);
        ValidateBitVec(bitvec);
        if (idx >= bitvec->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bitvec->length);
        }
        u64 byte_idx   = BIT_INDEX(idx);
        ValidateBitVec(bitvec);
        if (idx >= bitvec->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bitvec->length);
        }
        u64 byte_idx   = BIT_INDEX(idx);
        ValidateBitVec(bitvec);
        if (bitvec->length == 0) {
            LOG_FATAL("Cannot pop from empty bitvector");
        }
        bool value = BitVecGet(bitvec, bitvec->length - 1);
        ValidateBitVec(bitvec);
        if (idx > bitvec->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bitvec->length);
        }
        // For now, implement as push + manual bit shifting (simple but not efficient)
        ValidateBitVec(bv);
        if (idx > bv->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bv->length);
        }
        if (count == 0) {
        ValidateBitVec(other);
        if (idx > bv->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bv->length);
        }
        if (other->length == 0) {
        ValidateBitVec(bv);
        if (idx > bv->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bv->length);
        }
        if (pattern_bits == 0 || pattern_bits > 8) {
        ValidateBitVec(bv);
        if (idx >= bv->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bv->length);
        }
        ValidateBitVec(bv);
        if (idx >= bv->length) {
            LOG_FATAL("Index {} exceeds bitvector length {}", idx, bv->length);
        }
        if (count == 0) {
    
        if (start1 + len > bv1->length) {
            LOG_FATAL("Range [{}:{}] exceeds bitvector1 length {}", start1, LVAL(start1 + len - 1), bv1->length);
        }
        if (start2 + len > bv2->length) {
        }
        if (start2 + len > bv2->length) {
            LOG_FATAL("Range [{}:{}] exceeds bitvector2 length {}", start2, LVAL(start2 + len - 1), bv2->length);
        }
    
        if (start1 + len > bv1->length) {
            LOG_FATAL("Range [{}:{}] exceeds bitvector1 length {}", start1, LVAL(start1 + len - 1), bv1->length);
        }
        if (start2 + len > bv2->length) {
        }
        if (start2 + len > bv2->length) {
            LOG_FATAL("Range [{}:{}] exceeds bitvector2 length {}", start2, LVAL(start2 + len - 1), bv2->length);
        }
    BitVec BitVecFromStr(const char *str) {
        if (!str) {
            LOG_FATAL("str is NULL");
        }
        ValidateBitVec(bv);
        if (!bytes) {
            LOG_FATAL("bytes is NULL");
        }
        if (max_len == 0) {
        }
        if (max_len == 0) {
            LOG_FATAL("max_len is 0");
        }
        if (bv->length == 0) {
    BitVec BitVecFromBytes(const u8 *bytes, u64 bit_len) {
        if (!bytes) {
            LOG_FATAL("bytes is NULL");
        }
    
        if (!results || max_results == 0) {
            LOG_FATAL("results is NULL or max_results is 0");
        }
        ValidateBitVec(bv);
        if (!runs || !values || max_runs == 0) {
            LOG_FATAL("invalid arguments");
        }
            FREE(prev_row);
            FREE(curr_row);
            LOG_FATAL("Memory allocation failed");
        }
        ValidateBitVec(bv);
        if (!pattern) {
            LOG_FATAL("pattern is NULL");
        }
        ValidateBitVec(bv);
        if (!patterns) {
            LOG_FATAL("invalid BitVecs object provided");
        }
        ValidateBitVec(bv);
        if (!patterns) {
            LOG_FATAL("invalid arguments");
        }
    void ValidateBitVec(const BitVec *bv) {
        if (!(bv)) {
            LOG_FATAL("Invalid bitvec object: NULL.");
        }
        if ((bv)->__magic != MISRA_BITVEC_MAGIC) {
        }
        if ((bv)->__magic != MISRA_BITVEC_MAGIC) {
            LOG_FATAL("Invalid bitvec. Either uninitialized or curropted!");
        }
        if ((bv)->length > (bv)->capacity) {
        }
        if ((bv)->length > (bv)->capacity) {
            LOG_FATAL("Invalid bitvec object: length > capacity.");
        }
        if ((bv)->length > 0 && !(bv)->data) {
        }
        if ((bv)->length > 0 && !(bv)->data) {
            LOG_FATAL("Invalid bitvec object: length > 0 but data is NULL.");
        }
        if ((bv)->capacity > 0 && (bv)->byte_size * 8 < (bv)->capacity) {
        }
        if ((bv)->capacity > 0 && (bv)->byte_size * 8 < (bv)->capacity) {
            LOG_FATAL("Invalid bitvec object: byte_u64 too small for capacity.");
        }
        if ((bv)->data) {
    static size map_validate_policy_index(size idx, size capacity, const char *callback_name) {
        if (capacity && idx >= capacity) {
            LOG_FATAL("{} returned index {} for capacity {}", callback_name, idx, capacity);
        }
    
        if (!policy) {
            LOG_FATAL("Expected a valid MapPolicy pointer");
        }
    
        if (!policy->name || !policy->name[0]) {
            LOG_FATAL("MapPolicy must have a non-empty name");
        }
    
        if (!policy->should_rehash || !policy->next_capacity || !policy->first_index || !policy->next_index) {
            LOG_FATAL("MapPolicy '{}' must provide all required callbacks", policy->name);
        }
    
        if (policy->max_probe_count == 0) {
            LOG_FATAL("MapPolicy '{}' must provide a non-zero max_probe_count", policy->name);
        }
    
            if ((next0 == 0) && ((length != 0) || (capacity != 0) || (tombstones != 0))) {
                LOG_FATAL("MapPolicy '{}' returned zero capacity for a non-empty snapshot", policy->name);
            }
    
            if ((next_same != 0) && (next_same < length)) {
                LOG_FATAL("MapPolicy '{}' returned capacity smaller than current length", policy->name);
            }
    
            if (next_more < ((size)length + 1)) {
                LOG_FATAL("MapPolicy '{}' returned capacity smaller than requested minimum entries", policy->name);
            }
        }
    
                if (next == first) {
                    LOG_FATAL("MapPolicy '{}' produced a stuck probe sequence for capacity {}", policy->name, capacity);
                }
            }
        limit = map->policy.max_probe_count;
        if (limit == 0) {
            LOG_FATAL("Map policy '{}' has invalid max_probe_count", map->policy.name);
        }
    
        if (insert_idx >= map->capacity) {
            LOG_FATAL("Failed to insert raw map entry during rehash");
        }
    void validate_map(const GenericMap *map) {
        if (!map) {
            LOG_FATAL("Expected a valid Map pointer");
        }
    
        if (map->__magic != MISRA_MAP_MAGIC) {
            LOG_FATAL("Map is uninitialized or corrupted");
        }
    
        if (!map->key_compare || !map->key_hash) {
            LOG_FATAL("Map must have valid key compare and key hash callbacks");
        }
    
        if (map->length > map->capacity) {
            LOG_FATAL("Map length cannot exceed capacity");
        }
    
        if ((map->length + map->tombstones) > map->capacity) {
            LOG_FATAL("Map occupied slots and tombstones cannot exceed capacity");
        }
        if (!map->capacity) {
            if (map->entries || map->states) {
                LOG_FATAL("Map with zero capacity must not have allocated storage");
            }
            return;
    
        if (!map->entries || !map->states) {
            LOG_FATAL("Map storage is corrupted");
        }
    }
    
        if (new_capacity < (n > map->length ? n : (size)map->length)) {
            LOG_FATAL("Map policy '{}' returned insufficient capacity {}", policy.name, new_capacity);
        }
    
        if (!map->value_compare) {
            LOG_FATAL("MapContainsPair requires a value comparator");
        }
    
        if (!map->value_compare) {
            LOG_FATAL("MapRemovePair requires a value comparator");
        }
    
        if (!predicate) {
            LOG_FATAL("MapRemoveIf requires a predicate");
        }
    
        if (!predicate) {
            LOG_FATAL("MapRetainIf requires a predicate");
        }
            }
        } else {
            LOG_FATAL("Invalid direction");
            return 0;
        }
    void validate_iter(GenericIter *i) {
        if (((i)->dir != -1 && (i)->dir != 1) || !(i)->alignment || !(i)->length || (i)->pos >= (i)->length) {
            LOG_FATAL("Invalid iter object.");
        }
        (void)(*(char *)(void *)((i)->data));
    void SysProcWait(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
        }
    SysProcStatus SysProcWaitFor(SysProc *proc, u64 timeout_ms) {
        if (!proc) {
            LOG_FATAL("Invalid arguments");
        }
    void SysProcTerminate(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
        }
    void SysProcDestroy(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
        }
        SysProcTerminate(proc);
    i32 SysProcWriteToStdin(SysProc *proc, Str *buf) {
        if (!proc || !buf) {
            LOG_FATAL("Invalid arguments");
        }
    i32 sys_proc_read_internal(SysProc *proc, Str *buf, bool is_stdout) {
        if (!proc || !buf) {
            LOG_FATAL("Invalid argument");
        }
    i32 SysProcGetId(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
        }
    i32 SysProcIsRunning(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
        }
    i32 SysProcGetExitCode(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
        }
    Str *SysGetCurrentExecutablePath(Str *exe_path) {
        if (!exe_path) {
            LOG_FATAL("Invalid arguments: exe_path is NULL");
        }
    SysDirEntry *SysDirEntryInitCopy(SysDirEntry *dst, SysDirEntry *src) {
        if (!dst || !src) {
            LOG_FATAL("invalid arguments.");
        }
    SysDirEntry *SysDirEntryDeinitCopy(SysDirEntry *copy) {
        if (!copy) {
            LOG_FATAL("invalid arguments.");
        }
    SysDirContents SysGetDirContents(const char *path) {
        if (!path) {
            LOG_FATAL("Invalid argument");
        }
    SysDirContents SysGetDirContents(const char *path) {
        if (!path) {
            LOG_FATAL("invalid arguments.");
        }
            Scope(&config, StrDeinit, {
                if (!ReadCompleteFile(config_path, &config.data, &config.length, &config.capacity)) {
                    LOG_FATAL("Failed to read config file.");
                }
                StrIter json = StrIterFromStr(config);
    int main(int argc, char **argv) {
        if (argc < 2) {
            LOG_FATAL("USAGE: {} {}", argv[0], argv[1]);
        }
        // for an invalid elf magic, any subsequent fields will be zero, and hence will be invalid
        if (eh.meta.class != ELF_CLASS_64) {
            LOG_FATAL("Only 64-bit binaries supported for now. Class for provided binary is = {}", eh.meta.class);
        }
        BitVecPush(&pattern, true);
    
        BitVecFindPattern(NULL, &pattern); // Should cause LOG_FATAL
    
        BitVecDeinit(&pattern);
        BitVecPush(&source, false);
    
        BitVecFindPattern(&source, NULL); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindLastPattern(NULL, &pattern); // Should cause LOG_FATAL
    
        BitVecDeinit(&pattern);
        BitVecPush(&source, false);
    
        BitVecFindLastPattern(&source, NULL); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
    
        // Don't create pattern BitVec since we're testing NULL source validation
        BitVecFindAllPattern(NULL, (BitVec *)0x1, results, 10); // Should cause LOG_FATAL
    
        return true;
        BitVecPush(&source, false);
    
        BitVecFindAllPattern(&source, NULL, results, 10); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindAllPattern(&source, &pattern, NULL, 10); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindAllPattern(&source, &pattern, results, 0); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindPattern(NULL, &pattern); // Should cause LOG_FATAL
    
        BitVecDeinit(&pattern);
        BitVecPush(&source, false);
    
        BitVecFindPattern(&source, NULL); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindLastPattern(NULL, &pattern); // Should cause LOG_FATAL
    
        BitVecDeinit(&pattern);
        BitVecPush(&source, false);
    
        BitVecFindLastPattern(&source, NULL); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
    
        // Don't create pattern BitVec since we're testing NULL source validation
        BitVecFindAllPattern(NULL, (BitVec *)0x1, results, 10); // Should cause LOG_FATAL
    
        return true;
        BitVecPush(&source, false);
    
        BitVecFindAllPattern(&source, NULL, results, 10); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindAllPattern(&source, &pattern, NULL, 10); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
        BitVecPush(&pattern, true);
    
        BitVecFindAllPattern(&source, &pattern, results, 0); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
            {                                                                                                              \
                if (varr == NULL) {                                                                                        \
                    LOG_FATAL("Expected a valid pointer");                                                                 \
                }                                                                                                          \
                VEC_DATATYPE(v) __tmp_val_##__LINE__ = *(varr);                                                            \
            {                                                                                                              \
                if (varr == NULL) {                                                                                        \
                    LOG_FATAL("Expected a valid pointer");                                                                 \
                }                                                                                                          \
                VEC_DATATYPE(v) __tmp_val_##__LINE__ = *(varr);                                                            \
            {                                                                                                              \
                if (varr == NULL) {                                                                                        \
                    LOG_FATAL("Expected a valid pointer");                                                                 \
                }                                                                                                          \
                VEC_DATATYPE(v) __tmp_val_##__LINE__ = *(varr);                                                            \
            {                                                                                                              \
                if (varr == NULL) {                                                                                        \
                    LOG_FATAL("Expected a valid pointer");                                                                 \
                }                                                                                                          \
                VEC_DATATYPE(v) __tmp_val_##__LINE__ = *(varr);                                                            \
Last updated on