Skip to content

Commit

Permalink
Replace assert(0) with abort() or cpu_abort()
Browse files Browse the repository at this point in the history
When building with -DNDEBUG, assert(0) will not stop execution
so it must not be used for abnormal termination.

Use cpu_abort() when in CPU context, abort() otherwise.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
  • Loading branch information
blueswirl committed Mar 18, 2010
1 parent 609c1da commit 43dc2a6
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 56 deletions.
20 changes: 10 additions & 10 deletions block/vvfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
/* new file */
schedule_new_file(s, qemu_strdup(path), cluster_num);
else {
assert(0);
abort();
return 0;
}
}
Expand All @@ -1659,7 +1659,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
if (offset != mapping->info.file.offset + s->cluster_size
* (cluster_num - mapping->begin)) {
/* offset of this cluster in file chain has changed */
assert(0);
abort();
copy_it = 1;
} else if (offset == 0) {
const char* basename = get_basename(mapping->path);
Expand All @@ -1671,7 +1671,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,

if (mapping->first_mapping_index != first_mapping_index
&& mapping->info.file.offset > 0) {
assert(0);
abort();
copy_it = 1;
}

Expand Down Expand Up @@ -1837,7 +1837,7 @@ DLOG(fprintf(stderr, "check direntry %d: \n", i); print_direntry(direntries + i)
goto fail;
}
} else
assert(0); /* cluster_count = 0; */
abort(); /* cluster_count = 0; */

ret += cluster_count;
}
Expand Down Expand Up @@ -2458,7 +2458,7 @@ static int handle_commits(BDRVVVFATState* s)
commit_t* commit = array_get(&(s->commits), i);
switch(commit->action) {
case ACTION_RENAME: case ACTION_MKDIR:
assert(0);
abort();
fail = -2;
break;
case ACTION_WRITEOUT: {
Expand Down Expand Up @@ -2519,7 +2519,7 @@ static int handle_commits(BDRVVVFATState* s)
break;
}
default:
assert(0);
abort();
}
}
if (i > 0 && array_remove_slice(&(s->commits), 0, i))
Expand Down Expand Up @@ -2607,7 +2607,7 @@ static int do_commit(BDRVVVFATState* s)
ret = handle_renames_and_mkdirs(s);
if (ret) {
fprintf(stderr, "Error handling renames (%d)\n", ret);
assert(0);
abort();
return ret;
}

Expand All @@ -2618,21 +2618,21 @@ static int do_commit(BDRVVVFATState* s)
ret = commit_direntries(s, 0, -1);
if (ret) {
fprintf(stderr, "Fatal: error while committing (%d)\n", ret);
assert(0);
abort();
return ret;
}

ret = handle_commits(s);
if (ret) {
fprintf(stderr, "Error handling commits (%d)\n", ret);
assert(0);
abort();
return ret;
}

ret = handle_deletes(s);
if (ret) {
fprintf(stderr, "Error deleting\n");
assert(0);
abort();
return ret;
}

Expand Down
30 changes: 15 additions & 15 deletions hw/sh7750.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static uint32_t sh7750_mem_readb(void *opaque, target_phys_addr_t addr)
switch (addr) {
default:
error_access("byte read", addr);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ static uint32_t sh7750_mem_readw(void *opaque, target_phys_addr_t addr)
return 0;
default:
error_access("word read", addr);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -287,7 +287,7 @@ static uint32_t sh7750_mem_readl(void *opaque, target_phys_addr_t addr)
return s->cpu->prr;
default:
error_access("long read", addr);
assert(0);
abort();
}
}

Expand All @@ -303,7 +303,7 @@ static void sh7750_mem_writeb(void *opaque, target_phys_addr_t addr,
}

error_access("byte write", addr);
assert(0);
abort();
}

static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr,
Expand Down Expand Up @@ -349,12 +349,12 @@ static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr,
s->gpioic = mem_value;
if (mem_value != 0) {
fprintf(stderr, "I/O interrupts not implemented\n");
assert(0);
abort();
}
return;
default:
error_access("word write", addr);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -433,7 +433,7 @@ static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr,
return;
default:
error_access("long write", addr);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -618,7 +618,7 @@ static struct intc_group groups_irl[] = {

static uint32_t invalid_read(void *opaque, target_phys_addr_t addr)
{
assert(0);
abort();

return 0;
}
Expand All @@ -635,7 +635,7 @@ static uint32_t sh7750_mmct_readl(void *opaque, target_phys_addr_t addr)
case MM_ITLB_ADDR:
case MM_ITLB_DATA:
/* XXXXX */
assert(0);
abort();
break;
case MM_OCACHE_ADDR:
case MM_OCACHE_DATA:
Expand All @@ -644,10 +644,10 @@ static uint32_t sh7750_mmct_readl(void *opaque, target_phys_addr_t addr)
case MM_UTLB_ADDR:
case MM_UTLB_DATA:
/* XXXXX */
assert(0);
abort();
break;
default:
assert(0);
abort();
}

return ret;
Expand All @@ -656,7 +656,7 @@ static uint32_t sh7750_mmct_readl(void *opaque, target_phys_addr_t addr)
static void invalid_write(void *opaque, target_phys_addr_t addr,
uint32_t mem_value)
{
assert(0);
abort();
}

static void sh7750_mmct_writel(void *opaque, target_phys_addr_t addr,
Expand All @@ -672,7 +672,7 @@ static void sh7750_mmct_writel(void *opaque, target_phys_addr_t addr,
case MM_ITLB_ADDR:
case MM_ITLB_DATA:
/* XXXXX */
assert(0);
abort();
break;
case MM_OCACHE_ADDR:
case MM_OCACHE_DATA:
Expand All @@ -683,10 +683,10 @@ static void sh7750_mmct_writel(void *opaque, target_phys_addr_t addr,
break;
case MM_UTLB_DATA:
/* XXXXX */
assert(0);
abort();
break;
default:
assert(0);
abort();
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions hw/sh_intc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)
}
}

assert(0);
abort();
}

#define INTC_MODE_NONE 0
Expand Down Expand Up @@ -181,7 +181,7 @@ static void sh_intc_locate(struct intc_desc *desc,
}
}

assert(0);
abort();
}

static void sh_intc_toggle_mask(struct intc_desc *desc, intc_enum id,
Expand Down Expand Up @@ -260,7 +260,7 @@ static void sh_intc_write(void *opaque, target_phys_addr_t offset,
case INTC_MODE_ENABLE_REG | INTC_MODE_IS_PRIO: break;
case INTC_MODE_DUAL_SET: value |= *valuep; break;
case INTC_MODE_DUAL_CLR: value = *valuep & ~value; break;
default: assert(0);
default: abort();
}

for (k = 0; k <= first; k++) {
Expand Down
4 changes: 2 additions & 2 deletions hw/sh_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val)
}

fprintf(stderr, "sh_serial: unsupported write to 0x%02x\n", offs);
assert(0);
abort();
}

static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs)
Expand Down Expand Up @@ -282,7 +282,7 @@ static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs)

if (ret & ~((1 << 16) - 1)) {
fprintf(stderr, "sh_serial: unsupported read from 0x%02x\n", offs);
assert(0);
abort();
}

return ret;
Expand Down
12 changes: 6 additions & 6 deletions hw/sm501.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static inline uint16_t get_hwc_color(SM501State *state, int crt, int index)
break;
default:
printf("invalid hw cursor color.\n");
assert(0);
abort();
}

switch (index) {
Expand Down Expand Up @@ -663,7 +663,7 @@ static uint32_t sm501_system_config_read(void *opaque, target_phys_addr_t addr)
default:
printf("sm501 system config : not implemented register read."
" addr=%x\n", (int)addr);
assert(0);
abort();
}

return ret;
Expand Down Expand Up @@ -713,7 +713,7 @@ static void sm501_system_config_write(void *opaque,
default:
printf("sm501 system config : not implemented register write."
" addr=%x, val=%x\n", (int)addr, value);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -843,7 +843,7 @@ static uint32_t sm501_disp_ctrl_read(void *opaque, target_phys_addr_t addr)
default:
printf("sm501 disp ctrl : not implemented register read."
" addr=%x\n", (int)addr);
assert(0);
abort();
}

return ret;
Expand Down Expand Up @@ -951,7 +951,7 @@ static void sm501_disp_ctrl_write(void *opaque,
default:
printf("sm501 disp ctrl : not implemented register write."
" addr=%x, val=%x\n", (int)addr, value);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -1097,7 +1097,7 @@ static void sm501_draw_crt(SM501State * s)
default:
printf("sm501 draw crt : invalid DC_CRT_CONTROL=%x.\n",
s->dc_crt_control);
assert(0);
abort();
break;
}

Expand Down
8 changes: 4 additions & 4 deletions hw/tc58128.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void handle_command(tc58128_dev * dev, uint8_t command)
break;
default:
fprintf(stderr, "unknown flash command 0x%02x\n", command);
assert(0);
abort();
}
}

Expand Down Expand Up @@ -110,12 +110,12 @@ static void handle_address(tc58128_dev * dev, uint8_t data)
break;
default:
/* Invalid data */
assert(0);
abort();
}
dev->address_cycle++;
break;
default:
assert(0);
abort();
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ static int tc58128_cb(uint16_t porta, uint16_t portb,
*periph_pdtra &= 0xff00;
*periph_pdtra |= handle_read(&tc58128_devs[dev]);
} else {
assert(0);
abort();
}
return 1;
}
Expand Down
1 change: 0 additions & 1 deletion linux-user/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ static void QEMU_NORETURN force_sig(int target_sig)
sigsuspend(&act.sa_mask);

/* unreachable */
assert(0);
abort();
}

Expand Down
3 changes: 1 addition & 2 deletions qdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ double qdict_get_double(const QDict *qdict, const char *key)
case QTYPE_QINT:
return qint_get_int(qobject_to_qint(obj));
default:
assert(0);
return 0.0;
abort();
}
}

Expand Down
2 changes: 1 addition & 1 deletion target-cris/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void do_interruptv10(CPUState *env)
break;

case EXCP_BUSFAULT:
assert(0);
cpu_abort(env, "Unhandled busfault");
break;

default:
Expand Down
Loading

0 comments on commit 43dc2a6

Please sign in to comment.