src/error.c
libhwbtc_error * error_add_v(libhwbtc_error * error, const char * format, va_list ap)
{
    if (format == NULL) { return error; }

    error = error_make_mutable(error);
    if (error == NULL || error->do_not_free) { return error; }

    if (error->message == NULL) { error->message = ""; }

    // Determine all the string lengths.
    size_t outer_message_length = 0;
    {
        char x[1];
        va_list ap2;
        va_copy(ap2, ap);
        int result = vsnprintf(x, 0, format, ap2);
        if (result > 0)
        {
            outer_message_length = result;
        }
        va_end(ap2);
    }
    size_t inner_message_length = strlen(error->message);
    size_t separator_length = (inner_message_length && outer_message_length) ? 2 : 0;
    size_t message_length = outer_message_length + separator_length + inner_message_length;

    char * message = malloc(message_length + 1);
    if (message == NULL)
    {
        libhwbtc_error_free(error);
        return &error_masked_by_no_memory;
    }

    // Assemble the message.
    vsnprintf(message, outer_message_length + 1, format, ap);
    strncpy(message + outer_message_length, "  ", separator_length + 1);
    strncpy(message + outer_message_length + separator_length,
        error->message, inner_message_length + 1);
    message[message_length] = 0;

    free(error->message);
    error->message = message;
    return error;
}
// Tries to add a message to the error.  After calling this, you
// should not use the error you passed as an input, because it might
// have been freed.
Tries to add a message to the error.  After calling this, you
should not use the error you passed as an input, because it might
have been freed.
Tries to add a message to the error . After calling this you should not use the error you passed as an input because it might have been freed .
libhwbtc_error * error_add_v(libhwbtc_error * error, const char * format, va_list ap)
{
    if (format == NULL) { return error; }
    error = error_make_mutable(error);
    if (error == NULL || error->do_not_free) { return error; }
    if (error->message == NULL) { error->message = ""; }
    size_t outer_message_length = 0;
    {
        char x[1];
        va_list ap2;
        va_copy(ap2, ap);
        int result = vsnprintf(x, 0, format, ap2);
        if (result > 0)
        {
            outer_message_length = result;
        }
        va_end(ap2);
    }
    size_t inner_message_length = strlen(error->message);
    size_t separator_length = (inner_message_length && outer_message_length) ? 2 : 0;
    size_t message_length = outer_message_length + separator_length + inner_message_length;
    char * message = malloc(message_length + 1);
    if (message == NULL)
    {
        libhwbtc_error_free(error);
        return &error_masked_by_no_memory;
    }
    vsnprintf(message, outer_message_length + 1, format, ap);
    strncpy(message + outer_message_length, "  ", separator_length + 1);
    strncpy(message + outer_message_length + separator_length,
        error->message, inner_message_length + 1);
    message[message_length] = 0;
    free(error->message);
    error->message = message;
    return error;
}
libhwbtc_error * error_add_v ( libhwbtc_error * error , const char * format , va_list ap ) { if ( format == NULL ) { return error ; } error = error_make_mutable ( error ) ; if ( error == NULL || error -> do_not_free ) { return error ; } if ( error -> message == NULL ) { error -> message = " " ; } size_t outer_message_length = 0 ; { char x [ 1 ] ; va_list ap2 ; va_copy ( ap2 , ap ) ; int result = vsnprintf ( x , 0 , format , ap2 ) ; if ( result > 0 ) { outer_message_length = result ; } va_end ( ap2 ) ; } size_t inner_message_length = strlen ( error -> message ) ; size_t separator_length = ( inner_message_length && outer_message_length ) ? 2 : 0 ; size_t message_length = outer_message_length + separator_length + inner_message_length ; char * message = malloc ( message_length + 1 ) ; if ( message == NULL ) { libhwbtc_error_free ( error ) ; return & error_masked_by_no_memory ; } vsnprintf ( message , outer_message_length + 1 , format , ap ) ; strncpy ( message + outer_message_length , " " , separator_length + 1 ) ; strncpy ( message + outer_message_length + separator_length , error -> message , inner_message_length + 1 ) ; message [ message_length ] = 0 ; free ( error -> message ) ; error -> message = message ; return error ; }
Tries to add a message to the error.
Tries to add a message to the error .
// Determine all the string lengths. // Assemble the message.