| 49 | } |
| 50 | |
| 51 | struct hc_error *hc_error_new(const char *message, ...) { |
| 52 | va_list args; |
| 53 | va_start(args, message); |
| 54 | |
| 55 | va_list tmp_args; |
| 56 | va_copy(tmp_args, args); |
| 57 | int len = vsnprintf(NULL, 0, message, tmp_args); |
| 58 | va_end(tmp_args); |
| 59 | |
| 60 | if (len < 0) { |
| 61 | vfprintf(stderr, message, args); |
| 62 | abort(); |
| 63 | } |
| 64 | |
| 65 | len++; |
| 66 | struct hc_error *e = malloc(sizeof(struct hc_error)); |
| 67 | e->message = malloc(len); |
| 68 | vsnprintf(e->message, len, message, args); |
| 69 | va_end(args); |
| 70 | return e; |
| 71 | } |
| 72 | |
| 73 | void hc_error_free(struct hc_error *e) { |
| 74 | free(e->message); |
nothing calls this directly
no outgoing calls
no test coverage detected