Got rid of assert() in write.c by soft means

This commit is contained in:
Thomas Schmitt 2006-10-09 08:43:15 +00:00
parent 5d0b8265b2
commit cf8aacb27d
5 changed files with 188 additions and 46 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2006.10.08.095016" #define Cdrskin_timestamP "2006.10.09.083438"

View File

@ -591,16 +591,18 @@ ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
45) libburn/toc.c: assert(0); /* unhandled! find out ccd's ++ 45) libburn/toc.c: assert(0); /* unhandled! find out ccd's
static write_clonecd2(): static write_clonecd2():
- defunct -, - unused - - defunct -, - unused -
=> ? mangle assert ? => mangle assert
ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
46) libburn/toc.c: assert(d->busy); ++ 46) libburn/toc.c: assert(d->busy);
toc_find_modes(): toc_find_modes():
The drive to work on is not marked busy The drive to work on is not marked busy
@ -608,22 +610,26 @@ Called by mmc_read_toc() alias read_toc() by ... burn_drive_grab()
: Severe Libburn Error : Severe Libburn Error
=> to be prevented on the higher levels => to be prevented on the higher levels
=> issue LIBDAX_MSGS_SEV_WARNING => delete assert
ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
47) libburn/util.c: assert(s); ++ 47) libburn/util.c: assert(s);
burn_strdup() burn_strdup()
Abort on NULL string which would elsewise cuase a SIGSEGV Abort on NULL string which would elsewise cause a SIGSEGV
Used once in enumerate_common() with a string that worked with open(2) before Used once in enumerate_common() with a string that worked with open(2) before
: Severe Libburn Error : Severe Libburn Error
=> delete assert => delete assert
ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
48) libburn/util.c: assert(s); ++ 48) libburn/util.c: assert(s);
burn_strndup(): - unused - burn_strndup(): - unused -
Same as 47 Same as 47
@ -631,9 +637,11 @@ Same as 47
=> return NULL => return NULL
=> delete assert => delete assert
ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
49) libburn/util.c: assert(n > 0); ++ 49) libburn/util.c: assert(n > 0);
burn_strndup(): - unused - burn_strndup(): - unused -
Prevent problems by negative copy length Prevent problems by negative copy length
@ -641,21 +649,24 @@ Prevent problems by negative copy length
=> return NULL => return NULL
=> delete assert => delete assert
ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
50) libburn/write.c: assert(0); ++ 50) libburn/write.c: assert(0);
static type_to_ctrl(): static type_to_ctrl():
Unsuitable mode to be converted into "ctrl" Unsuitable mode to be converted into "ctrl"
Called by static type_to_form() finally burn_create_toc_entries() Called by static type_to_form() finally burn_create_toc_entries()
: Severe Application Error : Severe Application Error
=> to be caught at higher levels => to be caught in burn_track_define_data by calling for test type_to_form()
=> issue LIBDAX_MSGS_SEV_WARNING => return -1;
=> fall back to data mode
ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
51) libburn/write.c: assert(0); ++ 51) libburn/write.c: assert(0);
libburn/write.c: assert(0); /* XXX someone's gonna want this sometime */ libburn/write.c: assert(0); /* XXX someone's gonna want this sometime */
static type_to_form(): static type_to_form():
Does not like BURN_MODE0 or BURN_MODE2 but tolerates unknown modes Does not like BURN_MODE0 or BURN_MODE2 but tolerates unknown modes
@ -663,23 +674,33 @@ Does not like BURN_MODE0 or BURN_MODE2 but tolerates unknown modes
Called by static burn_create_toc_entries() by burn_disc_write_sync() Called by static burn_create_toc_entries() by burn_disc_write_sync()
: Undocumented Libburn Restriction : Undocumented Libburn Restriction
=> Disallow BURN_MODE0 and BURN_MODE2 with API burn_track_define_data() => set *form = -1 , *ctladr = 0xff , return
=> issue LIBDAX_MSGS_SEV_WARNING => make function non-static
=> default to BURN_MODE1 => call for test in API burn_track_define_data()
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
52) libburn/write.c: assert(ptr); ++ 52) libburn/write.c: assert(ptr);
static add_cue(): static add_cue():
realloc() failed realloc() failed
Called by burn_create_toc_entries() by burn_disc_write_sync()
(burn_create_toc_entries is ignorant towards own potential memory problems)
(This could possibly really stay an abort() because the reason is
a plain failure of the system's memory management.)
: Severe System Error : Severe System Error
=> This could possibly really stay an abort() because the reason is => change return type of add_cue to int
a plain failure of the system's memory management. => react on return -1 in burn_create_toc_entries, return NULL on failure
=> abort burn_disc_write_sync() on NULL return
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
53) libburn/write.c: assert(d->toc_entry == NULL); ++ 53) libburn/write.c: assert(d->toc_entry == NULL);
burn_create_toc_entries(): burn_create_toc_entries():
Multiple usage of struct burn_drive.toc_entry Multiple usage of struct burn_drive.toc_entry
@ -688,19 +709,23 @@ This will probably trigger an abort with disc->sessions > 1
(disc->sessions is incremented in macro RESIZE() as "NEW##s") (disc->sessions is incremented in macro RESIZE() as "NEW##s")
: Design Problem : Design Problem
=> ? disallow multiple sessions ? ( => ? disallow multiple sessions ? )
=> ? leave assert in and wait what happens ? => replace assert by soft means and wait what happens
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
54) libburn/write.c: assert(0); ++ 54) libburn/write.c: assert(0);
burn_sector_length(): burn_sector_length():
Only BURN_AUDIO, BURN_MODE_RAW, BURN_MODE1 are allowed Only BURN_AUDIO, BURN_MODE_RAW, BURN_MODE1 are allowed
Called by get_sector(), convert_data(), ... Called by get_sector(), convert_data(), ...
=> Only allow BURN_AUDIO, BURN_MODE_RAW, BURN_MODE1 with API burn_track_define_data() => call burn_sector_length() for test in API burn_track_define_data()
=> delete assert => replace assert by -1
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

View File

@ -320,6 +320,9 @@ Range "scdbackup" : 0x00020000 to 0x0002ffff
0x00020112 (SORRY,HIGH) = Bad combination of write_type and block_type 0x00020112 (SORRY,HIGH) = Bad combination of write_type and block_type
0x00020113 (FATAL,HIGH) = Drive capabilities not inquired yet 0x00020113 (FATAL,HIGH) = Drive capabilities not inquired yet
0x00020114 (SORRY,HIGH) = Attempt to set ISRC with bad data 0x00020114 (SORRY,HIGH) = Attempt to set ISRC with bad data
0x00020115 (SORRY,HIGH) = Attempt to set track mode to unusable value
0x00020116 (FATAL,HIGH) = Track mode has unusable value
0x00020117 (FATAL,HIGH) = toc_entry of drive is already in use
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

View File

@ -206,6 +206,23 @@ void burn_structure_print_track(struct burn_track *t)
void burn_track_define_data(struct burn_track *t, int offset, int tail, void burn_track_define_data(struct burn_track *t, int offset, int tail,
int pad, int mode) int pad, int mode)
{ {
int type_to_form(int mode, unsigned char *ctladr, int *form);
int burn_sector_length(int tracktype);
unsigned char ctladr;
int form = -1; /* unchanged form will be considered an error too */
type_to_form(mode, &ctladr, &form);
if (form == -1 || burn_sector_length(mode) <= 0) {
char msg[160];
sprintf(msg, "Attempt to set track mode to unusable value %d",
mode);
libdax_msgs_submit(libdax_messenger, -1, 0x00020115,
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
msg, 0, 0);
return;
}
t->offset = offset; t->offset = offset;
t->pad = pad; t->pad = pad;
t->mode = mode; t->mode = mode;

View File

@ -2,7 +2,11 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <assert.h>
/* ts A61009 */
/* #include <a ssert.h> */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -22,6 +26,10 @@
#include "write.h" #include "write.h"
#include "options.h" #include "options.h"
#include "libdax_msgs.h"
extern struct libdax_msgs *libdax_messenger;
static int type_to_ctrl(int mode) static int type_to_ctrl(int mode)
{ {
int ctrl = 0; int ctrl = 0;
@ -36,7 +44,9 @@ static int type_to_ctrl(int mode)
if (mode & BURN_PREEMPHASIS) if (mode & BURN_PREEMPHASIS)
ctrl |= 1; ctrl |= 1;
} else } else
assert(0); /* ts A61008 */
/* a ssert(0); */
return -1;
if (mode & BURN_COPY) if (mode & BURN_COPY)
ctrl |= 2; ctrl |= 2;
@ -45,18 +55,40 @@ static int type_to_ctrl(int mode)
} }
/* only the ctrl nibble is set here (not adr) */ /* only the ctrl nibble is set here (not adr) */
static void type_to_form(int mode, unsigned char *ctladr, int *form) /* ts A61009 : removed "static" , reacted on type_to_ctrl() == -1
preserved ignorance towards unknown modes (for now) */
void type_to_form(int mode, unsigned char *ctladr, int *form)
{ {
*ctladr = type_to_ctrl(mode) << 4; int ret;
ret = type_to_ctrl(mode) << 4;
if (ret == -1) {
*ctladr = 0xff;
*form = -1;
return;
}
*ctladr = ret;
if (mode & BURN_AUDIO) if (mode & BURN_AUDIO)
*form = 0; *form = 0;
if (mode & BURN_MODE0) if (mode & BURN_MODE0) {
assert(0);
/* ts A61009 */
/* a ssert(0); */
*form = -1;
return;
}
if (mode & BURN_MODE1) if (mode & BURN_MODE1)
*form = 0x10; *form = 0x10;
if (mode & BURN_MODE2) if (mode & BURN_MODE2) {
assert(0); /* XXX someone's gonna want this sometime */
/* ts A61009 */
/* a ssert(0); */ /* XXX someone's gonna want this sometime */
*form = -1;
return;
}
if (mode & BURN_MODE_RAW) if (mode & BURN_MODE_RAW)
*form = 0; *form = 0;
if (mode & BURN_SUBCODE_P16) /* must be expanded to R96 */ if (mode & BURN_SUBCODE_P16) /* must be expanded to R96 */
@ -109,7 +141,9 @@ static void print_cue(struct cue_sheet *sheet)
#endif /* Libburn_write_with_print_cuE */ #endif /* Libburn_write_with_print_cuE */
static void add_cue(struct cue_sheet *sheet, unsigned char ctladr, /* ts A61009 : changed type from void to int */
/** @return 1 = success , <=0 failure */
static int add_cue(struct cue_sheet *sheet, unsigned char ctladr,
unsigned char tno, unsigned char indx, unsigned char tno, unsigned char indx,
unsigned char form, unsigned char scms, int lba) unsigned char form, unsigned char scms, int lba)
{ {
@ -121,7 +155,17 @@ static void add_cue(struct cue_sheet *sheet, unsigned char ctladr,
sheet->count++; sheet->count++;
ptr = realloc(sheet->data, sheet->count * 8); ptr = realloc(sheet->data, sheet->count * 8);
assert(ptr);
/* ts A61009 */
/* a ssert(ptr); */
if (ptr == NULL) {
libdax_msgs_submit(libdax_messenger, -1, 0x00020111,
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
"Could not allocate new auxiliary object (cue_sheet->data)",
0, 0);
return -1;
}
sheet->data = ptr; sheet->data = ptr;
unit = sheet->data + (sheet->count - 1) * 8; unit = sheet->data + (sheet->count - 1) * 8;
unit[0] = ctladr; unit[0] = ctladr;
@ -132,12 +176,13 @@ static void add_cue(struct cue_sheet *sheet, unsigned char ctladr,
unit[5] = m; unit[5] = m;
unit[6] = s; unit[6] = s;
unit[7] = f; unit[7] = f;
return 1;
} }
struct cue_sheet *burn_create_toc_entries(struct burn_write_opts *o, struct cue_sheet *burn_create_toc_entries(struct burn_write_opts *o,
struct burn_session *session) struct burn_session *session)
{ {
int i, m, s, f, form, pform, runtime = -150; int i, m, s, f, form, pform, runtime = -150, ret;
unsigned char ctladr; unsigned char ctladr;
struct burn_drive *d; struct burn_drive *d;
struct burn_toc_entry *e; struct burn_toc_entry *e;
@ -149,17 +194,47 @@ struct cue_sheet *burn_create_toc_entries(struct burn_write_opts *o,
d = o->drive; d = o->drive;
sheet = malloc(sizeof(struct cue_sheet)); sheet = malloc(sizeof(struct cue_sheet));
/* ts A61009 : react on failures of malloc(), add_cue_sheet()
type_to_form() */
if (sheet == NULL) {
libdax_msgs_submit(libdax_messenger, -1, 0x00020111,
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
"Could not allocate new auxiliary object (cue_sheet)",
0, 0);
return NULL;
}
sheet->data = NULL; sheet->data = NULL;
sheet->count = 0; sheet->count = 0;
type_to_form(tar[0]->mode, &ctladr, &form); type_to_form(tar[0]->mode, &ctladr, &form);
add_cue(sheet, ctladr | 1, 0, 0, 1, 0, runtime); if (form == -1) {
add_cue(sheet, ctladr | 1, 1, 0, form, 0, runtime); libdax_msgs_submit(libdax_messenger, -1, 0x00020116,
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
"Track mode has unusable value", 0, 0);
goto failed;
}
ret = add_cue(sheet, ctladr | 1, 0, 0, 1, 0, runtime);
if (ret <= 0)
goto failed;
ret = add_cue(sheet, ctladr | 1, 1, 0, form, 0, runtime);
if (ret <= 0)
goto failed;
runtime += 150; runtime += 150;
burn_print(1, "toc for %d tracks:\n", ntr); burn_print(1, "toc for %d tracks:\n", ntr);
d->toc_entries = ntr + 3; d->toc_entries = ntr + 3;
assert(d->toc_entry == NULL);
/* ts A61009 */
/* a ssert(d->toc_entry == NULL); */
if (d->toc_entry != NULL) {
libdax_msgs_submit(libdax_messenger,
d->global_index, 0x00020117,
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
"toc_entry of drive is already in use", 0, 0);
goto failed;
}
d->toc_entry = malloc(d->toc_entries * sizeof(struct burn_toc_entry)); d->toc_entry = malloc(d->toc_entries * sizeof(struct burn_toc_entry));
e = d->toc_entry; e = d->toc_entry;
memset((void *)e, 0, d->toc_entries * sizeof(struct burn_toc_entry)); memset((void *)e, 0, d->toc_entries * sizeof(struct burn_toc_entry));
@ -187,7 +262,12 @@ struct cue_sheet *burn_create_toc_entries(struct burn_write_opts *o,
for (i = 0; i < ntr; i++) { for (i = 0; i < ntr; i++) {
type_to_form(tar[i]->mode, &ctladr, &form); type_to_form(tar[i]->mode, &ctladr, &form);
if (pform != form) { if (pform != form) {
add_cue(sheet, ctladr | 1, i + 1, 0, form, 0, runtime);
ret = add_cue(sheet, ctladr | 1, i + 1, 0, form, 0,
runtime);
if (ret <= 0)
goto failed;
runtime += 150; runtime += 150;
/* XXX fix pregap interval 1 for data tracks */ /* XXX fix pregap interval 1 for data tracks */
/* ts A60813 silence righteous compiler warning about C++ style comments /* ts A60813 silence righteous compiler warning about C++ style comments
@ -210,7 +290,11 @@ struct cue_sheet *burn_create_toc_entries(struct burn_write_opts *o,
e[3 + i].control = type_to_ctrl(tar[i]->mode); e[3 + i].control = type_to_ctrl(tar[i]->mode);
burn_print(1, "track %d control %d\n", tar[i]->mode, burn_print(1, "track %d control %d\n", tar[i]->mode,
e[3 + i].control); e[3 + i].control);
add_cue(sheet, ctladr | 1, i + 1, 1, form, 0, runtime);
ret = add_cue(sheet, ctladr | 1, i + 1, 1, form, 0, runtime);
if (ret <= 0)
goto failed;
runtime += burn_track_get_sectors(tar[i]); runtime += burn_track_get_sectors(tar[i]);
/* if we're padding, we'll clear any current shortage. /* if we're padding, we'll clear any current shortage.
if we're not, we'll slip toc entries by a sector every time our if we're not, we'll slip toc entries by a sector every time our
@ -240,8 +324,15 @@ XXX this is untested :)
burn_print(1, "point %d (%02d:%02d:%02d)\n", burn_print(1, "point %d (%02d:%02d:%02d)\n",
d->toc_entry[i].point, d->toc_entry[i].pmin, d->toc_entry[i].point, d->toc_entry[i].pmin,
d->toc_entry[i].psec, d->toc_entry[i].pframe); d->toc_entry[i].psec, d->toc_entry[i].pframe);
add_cue(sheet, ctladr | 1, 0xAA, 1, 1, 0, runtime); ret = add_cue(sheet, ctladr | 1, 0xAA, 1, 1, 0, runtime);
if (ret <= 0)
goto failed;
return sheet; return sheet;
failed:;
if (sheet != NULL)
free((char *) sheet);
return NULL;
} }
int burn_sector_length(int tracktype) int burn_sector_length(int tracktype)
@ -252,8 +343,9 @@ int burn_sector_length(int tracktype)
return 2352; return 2352;
if (tracktype & BURN_MODE1) if (tracktype & BURN_MODE1)
return 2048; return 2048;
assert(0); /* ts A61009 */
return 12345; /* a ssert(0); */
return -1;
} }
int burn_subcode_length(int tracktype) int burn_subcode_length(int tracktype)
@ -493,6 +585,11 @@ return crap. so we send the command, then ignore the result.
d->progress.tracks = disc->session[i]->tracks; d->progress.tracks = disc->session[i]->tracks;
sheet = burn_create_toc_entries(o, disc->session[i]); sheet = burn_create_toc_entries(o, disc->session[i]);
/* ts A61009 */
if (sheet == NULL)
goto fail;
/* print_cue(sheet);*/ /* print_cue(sheet);*/
if (o->write_type == BURN_WRITE_SAO) if (o->write_type == BURN_WRITE_SAO)
d->send_cue_sheet(d, sheet); d->send_cue_sheet(d, sheet);