From 7384b2de1e351e2b34d5154f0195d61fc0093fb4 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 3 Jul 2020 19:36:27 -0400 Subject: [PATCH] fix: harden panic logic --- runtime/include/panic.h | 15 +++++++++++++++ runtime/src/priority_queue.c | 11 +++-------- 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 runtime/include/panic.h diff --git a/runtime/include/panic.h b/runtime/include/panic.h new file mode 100644 index 0000000..538f27a --- /dev/null +++ b/runtime/include/panic.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include + +__attribute__((noreturn)) void +panic(const char *format, ...) +{ + va_list args; + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + exit(EXIT_FAILURE); +} \ No newline at end of file diff --git a/runtime/src/priority_queue.c b/runtime/src/priority_queue.c index 0533f89..6845629 100644 --- a/runtime/src/priority_queue.c +++ b/runtime/src/priority_queue.c @@ -4,7 +4,8 @@ #include #include -#include +#include "panic.h" +#include "priority_queue.h" /**************************** * Private Helper Functions * @@ -161,13 +162,7 @@ priority_queue_enqueue(struct priority_queue *self, void *value, char *name) int pre_length = self->first_free - 1; - if (priority_queue_append(self, value) == -1) { - printf("Priority Queue is full"); - fflush(stdout); - exit(EXIT_FAILURE); - ck_spinlock_fas_unlock(&self->lock); - return -1; - } + if (priority_queue_append(self, value) == -1) panic("Priority Queue is full"); int post_length = self->first_free - 1;