Mercurial > hg > audiodb
changeset 403:7038f31124d1 api-inversion
Better error-checking for operations which write to the database.
When I said /* FIXME: we should probably include... */ it hadn't
occurred to me that I had already included the relevant "..." (in this
case, the flags field in struct adb, which does contain the O_RDONLY /
O_RDWR flag which was used to open the database). Sometimes I am
pleasantly surprised with my foresight.
author | mas01cr |
---|---|
date | Wed, 03 Dec 2008 17:40:17 +0000 |
parents | 58b88ab69424 |
children | 1fb8bee777e5 |
files | l2norm.cpp power.cpp |
diffstat | 2 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/l2norm.cpp Wed Dec 03 17:40:15 2008 +0000 +++ b/l2norm.cpp Wed Dec 03 17:40:17 2008 +0000 @@ -53,6 +53,9 @@ int audiodb_l2norm(adb_t *adb) { adb_header_t *header = adb->header; + if(!(adb->flags & O_RDWR)) { + return 1; + } if(header->flags & O2_FLAG_L2NORM) { /* non-error code for forthcoming backwards-compatibility * reasons */
--- a/power.cpp Wed Dec 03 17:40:15 2008 +0000 +++ b/power.cpp Wed Dec 03 17:40:17 2008 +0000 @@ -5,9 +5,9 @@ } int audiodb_power(adb_t *adb) { - /* FIXME: we should probably include in adb_t information about - * which mode (O_RDONLY|O_RDWR) the database was opened, so that we - * can check that it's writeable. */ + if(!(adb->flags & O_RDWR)) { + return 1; + } if(adb->header->length > 0) { return 1; }