Mercurial > hg > audiodb
diff open.cpp @ 596:6ad0a6e67d4c
Take advantage of those new handy _or_goto_error macros
Use them in various places where previously we either elided the error
checking (various lseek() calls) or used a combination of calls
(replaced by malloc_and_fill_or_goto_error()).
In the process, fix what is probably a bug (or else introduce one, but I
don't think so): audiodb_track_id_datum() computed the offset into the
timesTable wrongly, forgetting to multiply by 2. (TODO: this should be
easily testable using the API).
Now all of LIBOBJS can be produced by my (Debian's) mingw32
cross-compiler, except for lshlib.o.
author | mas01cr |
---|---|
date | Tue, 11 Aug 2009 21:42:49 +0000 |
parents | cfa74bcc1249 |
children | b1723ae7675e |
line wrap: on
line diff
--- a/open.cpp Tue Aug 11 21:42:44 2009 +0000 +++ b/open.cpp Tue Aug 11 21:42:49 2009 +0000 @@ -28,12 +28,7 @@ if(adb->header->length > 0) { unsigned nfiles = adb->header->numFiles; key_table_length = align_page_up(nfiles * ADB_FILETABLE_ENTRY_SIZE); - key_table = (char *)malloc(key_table_length); - if(!key_table) { - goto error; - } - lseek_set_or_goto_error(adb->fd, adb->header->fileTableOffset); - read_or_goto_error(adb->fd, key_table, key_table_length); + malloc_and_fill_or_goto_error(char *, key_table, adb->header->fileTableOffset, key_table_length); for (unsigned int k = 0; k < nfiles; k++) { adb->keys->push_back(key_table + k*ADB_FILETABLE_ENTRY_SIZE); (*adb->keymap)[(key_table + k*ADB_FILETABLE_ENTRY_SIZE)] = k; @@ -44,9 +39,7 @@ return 0; error: - if(key_table) { - free(key_table); - } + maybe_free(key_table); return 1; } @@ -56,12 +49,7 @@ if(adb->header->length > 0) { unsigned nfiles = adb->header->numFiles; track_table_length = align_page_up(nfiles * ADB_TRACKTABLE_ENTRY_SIZE); - track_table = (uint32_t *) malloc(track_table_length); - if (!track_table) { - goto error; - } - lseek_set_or_goto_error(adb->fd, adb->header->trackTableOffset); - read_or_goto_error(adb->fd, track_table, track_table_length); + malloc_and_fill_or_goto_error(uint32_t *, track_table, adb->header->trackTableOffset, track_table_length); off_t offset = 0; for (unsigned int k = 0; k < nfiles; k++) { uint32_t track_length = track_table[k]; @@ -75,9 +63,7 @@ return 0; error: - if(track_table) { - free(track_table); - } + maybe_free(track_table); return 1; } @@ -146,12 +132,8 @@ error: if(adb) { - if(adb->header) { - free(adb->header); - } - if(adb->path) { - free(adb->path); - } + maybe_free(adb->header); + maybe_free(adb->path); if(adb->keys) { delete adb->keys; }