changeset 243:e75c52894630 src

* assert(0) does not always and the program (see NDEBUG) * use abort(), where we should really terminate * reversed return value of getbits_init (I prefer booleans)
author mroi
date Wed, 03 Mar 2004 16:50:42 +0000
parents f794e1c17947
children a27c81078c3c
files dvdread/nav_read.c vm/decoder.c vm/vm.c vm/vmcmd.c
diffstat 4 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/dvdread/nav_read.c	Wed Mar 03 16:48:36 2004 +0000
+++ b/dvdread/nav_read.c	Wed Mar 03 16:50:42 2004 +0000
@@ -19,9 +19,9 @@
 #include "config.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
-#include <assert.h>
 
 #include "bswap.h"
 #include "nav_types.h"
@@ -35,13 +35,13 @@
   uint8_t byte;
 } getbits_state_t;
 
-static int32_t getbits_init(getbits_state_t *state, uint8_t *start) {
-  if ((state == NULL) || (start == NULL)) return -1;
+static int getbits_init(getbits_state_t *state, uint8_t *start) {
+  if ((state == NULL) || (start == NULL)) return 0;
   state->start = start;
   state->bit_position = 0;
   state->byte_position = 0;
   state->byte = start[0];
-  return 0;
+  return 1;
 }
 
 /* Non-optimized getbits. */
@@ -51,7 +51,7 @@
   uint8_t byte=0;
   if (number_of_bits > 32) {
     printf("Number of bits > 32 in getbits\n");
-    assert(0);
+    abort();
   }
 
   if ((state->bit_position) > 0) {  /* Last getbits left us in the middle of a byte. */
@@ -128,7 +128,7 @@
 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
   int32_t i, j;
   getbits_state_t state;
-  if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */
+  if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
 
   /* pci pci_gi */
   pci->pci_gi.nv_pck_lbn = getbits(&state, 32 );
@@ -296,7 +296,7 @@
 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
   int i;
   getbits_state_t state;
-  if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */
+  if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
 
   /* dsi dsi gi */
   dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
--- a/vm/decoder.c	Wed Mar 03 16:48:36 2004 +0000
+++ b/vm/decoder.c	Wed Mar 03 16:50:42 2004 +0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2000, 2001 Martin Norbäck, Håkan Hjort
+ *               2002-2004 the dvdnav project
  * 
  * This file is part of libdvdnav, a DVD navigation library. It is modified
  * from a file originally part of the Ogle DVD player.
@@ -31,7 +32,6 @@
 #include <inttypes.h>
 #include <string.h>  /* For memset */
 #include "ifo_types.h" /* vm_cmd_t */
-#include <assert.h>
 
 #include "dvdnav_internal.h"
 
@@ -49,7 +49,7 @@
        (count < 0) ||
        (start < 0) ) {
     fprintf(MSG_OUT, "libdvdnav: Bad call to vm_getbits. Parameter out of range\n");
-    assert(0);
+    abort();
   }
   /* all ones, please */
   bit_mask = ~bit_mask;
@@ -512,7 +512,7 @@
       res = eval_special_instruction(&command, cond);
       if(res == -1) {
 	fprintf(MSG_OUT, "libdvdnav: Unknown Instruction!\n");
-	assert(0);
+	abort();
       }
       break;
     case 1: /*  Link/jump instructions */
@@ -566,7 +566,7 @@
       break;
     default: /* Unknown command */
       fprintf(MSG_OUT, "libdvdnav: WARNING: Unknown Command=%x\n", vm_getbits(&command, 63, 3));
-      assert(0);
+      abort();
   }
   /*  Check if there are bits not yet examined */
 
--- a/vm/vm.c	Wed Mar 03 16:48:36 2004 +0000
+++ b/vm/vm.c	Wed Mar 03 16:50:42 2004 +0000
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2000, 2001 Håkan Hjort
  * Copyright (C) 2001 Rich Wareham <richwareham@users.sourceforge.net>
+ *               2002-2004 the dvdnav project
  * 
  * This file is part of libdvdnav, a DVD navigation library. It is modified
  * from a file originally part of the Ogle DVD player.
@@ -866,8 +867,9 @@
   case VMGM_DOMAIN:
   case FP_DOMAIN:
     return vm->vmgi->vmgi_mat->vmgm_video_attr;
+  default:
+    abort();
   }
-  assert(0);
 }
 
 audio_attr_t vm_get_audio_attr(vm_t *vm, int streamN) {
@@ -879,8 +881,9 @@
   case VMGM_DOMAIN:
   case FP_DOMAIN:
     return vm->vmgi->vmgi_mat->vmgm_audio_attr;
+  default:
+    abort();
   }
-  assert(0);
 }
 
 subp_attr_t vm_get_subp_attr(vm_t *vm, int streamN) {
@@ -892,8 +895,9 @@
   case VMGM_DOMAIN:
   case FP_DOMAIN:
     return vm->vmgi->vmgi_mat->vmgm_subp_attr;
+  default:
+    abort();
   }
-  assert(0);
 }
 
 
@@ -1055,6 +1059,7 @@
     switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type) {
     case 0: /*  Not part of a block */
       assert(0);
+      break;
     case 1: /*  Angle block */
       /* Loop and check each cell instead? So we don't get outside the block? */
       (vm->state).cellN += (vm->state).AGL_REG - 1;
@@ -1159,6 +1164,7 @@
     switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type) {
     case 0: /*  Not part of a block */
       assert(0);
+      break;
     case 1: /*  Angle block */
       /* Skip the 'other' angles */
       (vm->state).cellN++;
@@ -1808,11 +1814,7 @@
     pgcit = get_MENU_PGCIT(vm, vm->vmgi, (vm->state).registers.SPRM[0]);
     break;
   default:
-    pgcit = NULL;    /* Should never hapen */
-    fprintf(MSG_OUT, "libdvdnav: get_PGCIT: Unknown domain:%d\n",
-             (vm->state).domain);
-    assert(0);
-    break;
+    abort();
   }
   
   return pgcit;
--- a/vm/vmcmd.c	Wed Mar 03 16:48:36 2004 +0000
+++ b/vm/vmcmd.c	Wed Mar 03 16:50:42 2004 +0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2000, 2001 Martin Norbäck, Håkan Hjort
+ *               2002-2004 the dvdnav project
  * 
  * This file is part of libdvdnav, a DVD navigation library. It is modified
  * from a file originally part of the Ogle DVD player.
@@ -29,7 +30,6 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <inttypes.h>
-#include <assert.h>
 
 #include "dvdnav_internal.h"