Replace uses of die() with err() + return

This commit is contained in:
Rodrigo Arias 2023-03-20 16:04:17 +01:00 committed by Rodrigo Arias Mallo
parent 0bdfea309a
commit 4a2a9ec685
9 changed files with 71 additions and 35 deletions

View File

@ -107,8 +107,10 @@ cpu_init_end(struct cpu *cpu)
}
for (int i = 0; i < CPU_CHAN_MAX; i++) {
if (chan_name[i] == NULL)
die("chan_name is null");
if (chan_name[i] == NULL) {
err("chan_name is null");
return -1;
}
chan_init(&cpu->chan[i], CHAN_SINGLE,
chan_fmt, cpu->gindex, chan_name[i]);

View File

@ -18,8 +18,12 @@ create_values(const struct model_pvt_spec *pvt,
if (q == NULL)
return 0;
for (const struct pcf_value_label *p = q; p->label != NULL; p++)
pcf_add_value(t, p->value, p->label);
for (const struct pcf_value_label *p = q; p->label != NULL; p++) {
if (pcf_add_value(t, p->value, p->label) == NULL) {
err("pcf_add_value failed");
return -1;
}
}
return 0;
}
@ -47,6 +51,10 @@ create_type(const struct model_pvt_spec *pvt,
}
struct pcf_type *pcftype = pcf_add_type(pcf, type, label);
if (pcftype == NULL) {
err("pcf_add_type failed");
return -1;
}
if (create_values(pvt, pcftype, i) != 0) {
err("create_values failed");

View File

@ -28,11 +28,15 @@ main(int argc, char *argv[])
return 1;
}
if (emu_init(emu, argc, argv) != 0)
die("emu_init failed\n");
if (emu_init(emu, argc, argv) != 0) {
err("emu_init failed\n");
return 1;
}
if (emu_connect(emu) != 0)
die("emu_connect failed\n");
if (emu_connect(emu) != 0) {
err("emu_connect failed\n");
return 1;
}
signal(SIGINT, stop_emulation);

View File

@ -69,7 +69,7 @@ copy_recursive(const char *src, const char *dst)
char *newdst = calloc(1, PATH_MAX);
if (newdst == NULL) {
die("calloc failed:");
err("calloc failed:");
return -1;
}

View File

@ -153,20 +153,26 @@ pcf_add_type(struct pcf *pcf, int type_id, const char *label)
{
struct pcf_type *pcftype = pcf_find_type(pcf, type_id);
if (pcftype != NULL)
die("PCF type %d already defined\n", type_id);
if (pcftype != NULL) {
err("PCF type %d already defined", type_id);
return NULL;
}
pcftype = calloc(1, sizeof(struct pcf_type));
if (pcftype == NULL)
die("calloc failed: %s\n", strerror(errno));
if (pcftype == NULL) {
err("calloc failed:");
return NULL;
}
pcftype->id = type_id;
pcftype->values = NULL;
pcftype->nvalues = 0;
int len = snprintf(pcftype->label, MAX_PCF_LABEL, "%s", label);
if (len >= MAX_PCF_LABEL)
die("PCF type label too long\n");
if (len >= MAX_PCF_LABEL) {
err("PCF type label too long");
return NULL;
}
HASH_ADD_INT(pcf->types, id, pcftype);
@ -193,18 +199,24 @@ pcf_add_value(struct pcf_type *type, int value, const char *label)
{
struct pcf_value *pcfvalue = pcf_find_value(type, value);
if (pcfvalue != NULL)
die("PCF value %d already in type %d\n", value, type->id);
if (pcfvalue != NULL) {
err("PCF value %d already in type %d", value, type->id);
return NULL;
}
pcfvalue = calloc(1, sizeof(struct pcf_value));
if (pcfvalue == NULL)
die("calloc failed: %s\n", strerror(errno));
if (pcfvalue == NULL) {
err("calloc failed:");
return NULL;
}
pcfvalue->value = value;
int len = snprintf(pcfvalue->label, MAX_PCF_LABEL, "%s", label);
if (len >= MAX_PCF_LABEL)
die("PCF value label too long\n");
if (len >= MAX_PCF_LABEL) {
err("PCF value label too long");
return NULL;
}
HASH_ADD_INT(type->values, value, pcfvalue);

View File

@ -34,8 +34,7 @@ prv_open(struct prv *prv, long nrows, const char *path)
FILE *f = fopen(path, "w");
if (f == NULL) {
die("cannot open file '%s' for writting: %s\n",
path, strerror(errno));
err("cannot open file '%s' for writting:", path);
return -1;
}

View File

@ -147,7 +147,7 @@ int
stream_clkoff_set(struct stream *stream, int64_t clkoff)
{
if (stream->cur_ev) {
die("cannot set clokoff in started stream '%s'",
err("cannot set clokoff in started stream '%s'",
stream->relpath);
return -1;
}

View File

@ -300,7 +300,10 @@ task_create_pcf_types(struct pcf_type *pcftype, struct task_type *types)
}
}
pcf_add_value(pcftype, tt->gid, tt->label);
if (pcf_add_value(pcftype, tt->gid, tt->label) == NULL) {
err("pcf_add_value failed");
return -1;
}
}
return ret;

View File

@ -163,8 +163,12 @@ create_values(struct pcf_type *t, int i)
if (q == NULL)
return 0;
for (const struct pcf_value_label *p = *q; p->label != NULL; p++)
pcf_add_value(t, p->value, p->label);
for (const struct pcf_value_label *p = *q; p->label != NULL; p++) {
if (pcf_add_value(t, p->value, p->label) == NULL) {
err("pcf_add_value failed");
return -1;
}
}
return 0;
}
@ -179,6 +183,10 @@ create_type(struct pcf *pcf, int i)
const char *label = pvt_name[i];
struct pcf_type *pcftype = pcf_add_type(pcf, type, label);
if (pcftype == NULL) {
err("pcf_add_type failed");
return -1;
}
if (create_values(pcftype, i) != 0) {
err("create_values failed");
@ -255,7 +263,7 @@ thread_set_state(struct thread *th, enum thread_state state)
{
/* The state must be updated when a cpu is set */
if (th->cpu == NULL) {
die("thread %d doesn't have a CPU", th->tid);
err("thread %d doesn't have a CPU", th->tid);
return -1;
}
@ -385,12 +393,12 @@ int
thread_set_cpu(struct thread *th, struct cpu *cpu)
{
if (cpu == NULL) {
err("thread_set_cpu: CPU is NULL\n");
err("CPU is NULL");
return -1;
}
if (th->cpu != NULL) {
err("thread_set_cpu: thread %d already has a CPU\n", th->tid);
err("thread %d already has a CPU", th->tid);
return -1;
}
@ -399,7 +407,7 @@ thread_set_cpu(struct thread *th, struct cpu *cpu)
/* Update cpu channel */
struct chan *c = &th->chan[TH_CHAN_CPU];
if (chan_set(c, value_int64(cpu->gindex)) != 0) {
err("thread_set_cpu: chan_set failed\n");
err("chan_set failed");
return -1;
}
@ -410,7 +418,7 @@ int
thread_unset_cpu(struct thread *th)
{
if (th->cpu == NULL) {
err("thread_unset_cpu: thread %d doesn't have a CPU\n", th->tid);
err("thread %d doesn't have a CPU", th->tid);
return -1;
}
@ -418,7 +426,7 @@ thread_unset_cpu(struct thread *th)
struct chan *c = &th->chan[TH_CHAN_CPU];
if (chan_set(c, value_null()) != 0) {
err("thread_set_cpu: chan_set failed\n");
err("chan_set failed");
return -1;
}
@ -429,7 +437,7 @@ int
thread_migrate_cpu(struct thread *th, struct cpu *cpu)
{
if (th->cpu == NULL) {
die("thread_migrate_cpu: thread %d doesn't have a CPU\n", th->tid);
err("thread %d doesn't have a CPU", th->tid);
return -1;
}
@ -437,7 +445,7 @@ thread_migrate_cpu(struct thread *th, struct cpu *cpu)
struct chan *c = &th->chan[TH_CHAN_CPU];
if (chan_set(c, value_int64(cpu->gindex)) != 0) {
err("thread_set_cpu: chan_set failed\n");
err("chan_set failed");
return -1;
}