# HG changeset patch # User mas01cr # Date 1228326017 0 # Node ID 7038f31124d11f44b414151b49b26f8ae38de10d # Parent 58b88ab69424a46ecc96916aab1876778e062024 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. diff -r 58b88ab69424 -r 7038f31124d1 l2norm.cpp --- 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 */ diff -r 58b88ab69424 -r 7038f31124d1 power.cpp --- 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; }