src/error.c
libhwbtc_error * libhwbtc_error_copy(const libhwbtc_error * src_error)
{
    if (src_error == NULL) { return NULL; }

    const char * src_message = src_error->message;
    if (src_message == NULL) { src_message = ""; }
    size_t message_length = strlen(src_message);

    size_t code_count = src_error->code_count;
    if (src_error->code_array == NULL) { code_count = 0; }

    // Allocate memory.
    libhwbtc_error * new_error = malloc(sizeof(libhwbtc_error));
    char * new_message = malloc(message_length + 1);
    uint32_t * new_code_array = malloc(code_count * sizeof(uint32_t));
    if (new_error == NULL || new_message == NULL ||
        (code_count != 0 && new_code_array == NULL))
    {
        free(new_error);
        free(new_message);
        free(new_code_array);
        return &error_masked_by_no_memory;
    }

    if (code_count != 0)
    {
        memcpy(new_code_array, src_error->code_array, code_count * sizeof(uint32_t));
    }
    strncpy(new_message, src_message, message_length + 1);
    new_error->do_not_free = false;
    new_error->message = new_message;
    new_error->code_count = code_count;
    new_error->code_array = new_code_array;
    return new_error;
}
// Copies the error.  If the input is not NULL, the output will always
// be not NULL, but it might be a immutable error (do_not_free=1).
Copies the error.  If the input is not NULL, the output will always
be not NULL, but it might be a immutable error (do_not_free=1).
Copies the error . If the input is not NULL the output will always be not NULL but it might be a immutable error ( do_not_free = 1 ) .
libhwbtc_error * libhwbtc_error_copy(const libhwbtc_error * src_error)
{
    if (src_error == NULL) { return NULL; }
    const char * src_message = src_error->message;
    if (src_message == NULL) { src_message = ""; }
    size_t message_length = strlen(src_message);
    size_t code_count = src_error->code_count;
    if (src_error->code_array == NULL) { code_count = 0; }
    libhwbtc_error * new_error = malloc(sizeof(libhwbtc_error));
    char * new_message = malloc(message_length + 1);
    uint32_t * new_code_array = malloc(code_count * sizeof(uint32_t));
    if (new_error == NULL || new_message == NULL ||
        (code_count != 0 && new_code_array == NULL))
    {
        free(new_error);
        free(new_message);
        free(new_code_array);
        return &error_masked_by_no_memory;
    }
    if (code_count != 0)
    {
        memcpy(new_code_array, src_error->code_array, code_count * sizeof(uint32_t));
    }
    strncpy(new_message, src_message, message_length + 1);
    new_error->do_not_free = false;
    new_error->message = new_message;
    new_error->code_count = code_count;
    new_error->code_array = new_code_array;
    return new_error;
}
libhwbtc_error * libhwbtc_error_copy ( const libhwbtc_error * src_error ) { if ( src_error == NULL ) { return NULL ; } const char * src_message = src_error -> message ; if ( src_message == NULL ) { src_message = " " ; } size_t message_length = strlen ( src_message ) ; size_t code_count = src_error -> code_count ; if ( src_error -> code_array == NULL ) { code_count = 0 ; } libhwbtc_error * new_error = malloc ( sizeof ( libhwbtc_error ) ) ; char * new_message = malloc ( message_length + 1 ) ; uint32_t * new_code_array = malloc ( code_count * sizeof ( uint32_t ) ) ; if ( new_error == NULL || new_message == NULL || ( code_count != 0 && new_code_array == NULL ) ) { free ( new_error ) ; free ( new_message ) ; free ( new_code_array ) ; return & error_masked_by_no_memory ; } if ( code_count != 0 ) { memcpy ( new_code_array , src_error -> code_array , code_count * sizeof ( uint32_t ) ) ; } strncpy ( new_message , src_message , message_length + 1 ) ; new_error -> do_not_free = false ; new_error -> message = new_message ; new_error -> code_count = code_count ; new_error -> code_array = new_code_array ; return new_error ; }
Copies the error.
Copies the error .
// Allocate memory.