refactor(ffi): check pointer arguments for NULL (#2624)
This changes all the extern C functions in `hyper::ffi` to check passed pointer arguments for being `NULL` before trying to use them. Before, we would just assume the programmer had passed a good pointer, which could result in segmentation faults. Now: - In debug builds, it will assert they aren't null, and so if they are, a message identifying the argument name will be printed and then the process will crash. - In release builds, it will still check for null, but if found, it will return early, with a return value indicating failure if the return type allows (such as returning NULL, or `HYPERE_INVALID_ARG`). Closes #2620
This commit is contained in:
@@ -153,8 +153,10 @@ static void print_informational(void *userdata, const hyper_response *resp) {
|
||||
|
||||
printf("\nInformational (1xx): %d\n", http_status);
|
||||
|
||||
const hyper_buf* headers = hyper_response_headers_raw(resp);
|
||||
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
|
||||
const hyper_buf *headers = hyper_response_headers_raw(resp);
|
||||
if (headers) {
|
||||
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
|
||||
}
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
|
||||
Reference in New Issue
Block a user