changeset 370:2d5c3f8e8c22

Merge gcc-4.3-cleanups branch (-r629:642, but I consider that branch as having served its purpose) onto the trunk. Now compiles cleanly even with a fairly picky gcc. I await version 4.4 with bated breath.
author mas01cr
date Wed, 12 Nov 2008 15:40:40 +0000
parents 94c18f128ce8
children 5eb5034b0577
files Makefile audioDB.cpp audioDB.h audioDB_API.h common.cpp create.cpp index.cpp insert.cpp lshlib.cpp query.cpp sample.cpp soap.cpp
diffstat 12 files changed, 185 insertions(+), 164 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Nov 12 10:21:06 2008 +0000
+++ b/Makefile	Wed Nov 12 15:40:40 2008 +0000
@@ -50,13 +50,13 @@
 	gcc -c $(CFLAGS) $<
 
 
-$(EXECUTABLE): cmdline.c $(OBJS) soapServer.cpp soapClient.cpp soapC.cpp
+$(EXECUTABLE): cmdline.o $(OBJS) soapServer.cpp soapClient.cpp soapC.cpp
 	g++ -c $(CFLAGS) $(GSOAP_INCLUDE) -Wall audioDB.cpp -DBINARY
 	g++ -o $(EXECUTABLE) $(CFLAGS) audioDB.o $^ $(LIBGSL) $(GSOAP_INCLUDE) $(GSOAP_CPP)
 
 
-$(LIBRARY): cmdline.c $(LIBOBJS)
-	g++ -c $(CFLAGS) $(GSOAP_INCLUDE) -Wall audioDB.cpp
+$(LIBRARY): cmdline.o $(LIBOBJS)
+	g++ -c $(CFLAGS) -Wall audioDB.cpp
 	g++ -shared -o $(LIBRARY) $(CFLAGS) $(LIBGSL) audioDB.o $^ 
 
 tags:
--- a/audioDB.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/audioDB.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -22,7 +22,7 @@
   return ( (a.trackID==b.trackID) && (a.qpos==b.qpos) && (a.spos==b.spos) );
 }
 
-audioDB::audioDB(const unsigned argc, const char *const argv[]): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[]): O2_AUDIODB_INITIALIZERS
 {
   if(processArgs(argc, argv)<0){
     printf("No command found.\n");
@@ -113,7 +113,7 @@
     error("Unrecognized command",command);
 }
 
-audioDB::audioDB(const unsigned argc, const char *const argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
     isServer = 1; // Set to make errors report over SOAP
@@ -129,7 +129,7 @@
   }
 }
 
-audioDB::audioDB(const unsigned argc, const char* const argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
     isServer = 1; // Set to make errors report over SOAP
@@ -145,7 +145,7 @@
   }
 }
 
-audioDB::audioDB(const unsigned argc, const char *const argv[], adb__lisztResponse *adbLisztResponse): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[], adb__lisztResponse *adbLisztResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
     isServer = 1; // Set to make errors report over SOAP
@@ -163,7 +163,7 @@
 
 
 //for the lib / API
-audioDB::audioDB(const unsigned argc, char* const argv[], int * apierror): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[], int * apierror): O2_AUDIODB_INITIALIZERS
 {
 
     try {
@@ -228,7 +228,7 @@
 }
 
 //for API status
-audioDB::audioDB(const unsigned argc, char* const argv[], cppstatusptr stat, int * apierror): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[], cppstatusptr stat, int * apierror): O2_AUDIODB_INITIALIZERS
 {
 
     try {
@@ -262,7 +262,7 @@
 
 
 //for API query
-audioDB::audioDB(const unsigned argc, char* const argv[],adb__queryResponse *adbQueryResponse, int * apierror): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[],adb__queryResponse *adbQueryResponse, int * apierror): O2_AUDIODB_INITIALIZERS
 {
 
     try {
@@ -344,7 +344,7 @@
   cleanup();
 }
 
-int audioDB::processArgs(const unsigned argc, const char *const argv[]){
+int audioDB::processArgs(const unsigned argc, const char *argv[]){
 
   if(argc<2){
     cmdline_parser_print_version ();
@@ -526,20 +526,23 @@
     return 0;
   }
        
-  if(args_info.INSERT_given){
+  if(args_info.INSERT_given) {
     command=COM_INSERT;
     dbName=args_info.database_arg;
     inFile=args_info.features_arg;
-    if(args_info.key_given)
-      if(!args_info.features_given)
+    if(args_info.key_given) {
+      if(!args_info.features_given) {
 	error("INSERT: '-k key' argument depends on '-f features'");
-      else
+      } else {
 	key=args_info.key_arg;
-    if(args_info.times_given){
+      }
+    }
+    if(args_info.times_given) {
       timesFileName=args_info.times_arg;
-      if(strlen(timesFileName)>0){
-        if(!(timesFile = new std::ifstream(timesFileName,std::ios::in)))
+      if(strlen(timesFileName)>0) {
+        if(!(timesFile = new std::ifstream(timesFileName,std::ios::in))) {
           error("Could not open times file for reading", timesFileName);
+	}
         usingTimes=1;
       }
     }
@@ -555,16 +558,17 @@
     return 0;
   }
   
-  if(args_info.BATCHINSERT_given){
+  if(args_info.BATCHINSERT_given) {
     command=COM_BATCHINSERT;
     dbName=args_info.database_arg;
     inFile=args_info.featureList_arg;
-    if(args_info.keyList_given)
-      if(!args_info.featureList_given)
+    if(args_info.keyList_given) {
+      if(!args_info.featureList_given) {
 	error("BATCHINSERT: '-K keyList' argument depends on '-F featureList'");
-      else
+      } else {
 	key=args_info.keyList_arg;     // INCONSISTENT NO CHECK
-
+      }
+    }
     /* TO DO: REPLACE WITH
       if(args_info.keyList_given){
       trackFileName=args_info.keyList_arg;
@@ -574,17 +578,17 @@
       AND UPDATE BATCHINSERT()
     */
     
-    if(args_info.timesList_given){
+    if(args_info.timesList_given) {
       timesFileName=args_info.timesList_arg;
-      if(strlen(timesFileName)>0){
+      if(strlen(timesFileName)>0) {
         if(!(timesFile = new std::ifstream(timesFileName,std::ios::in)))
           error("Could not open timesList file for reading", timesFileName);
         usingTimes=1;
       }
     }
-    if(args_info.powerList_given){
+    if(args_info.powerList_given) {
       powerFileName=args_info.powerList_arg;
-      if(strlen(powerFileName)>0){
+      if(strlen(powerFileName)>0) {
         if(!(powerFile = new std::ifstream(powerFileName,std::ios::in)))
           error("Could not open powerList file for reading", powerFileName);
         usingPower=1;
@@ -645,7 +649,7 @@
     command=COM_QUERY;
     dbName=args_info.database_arg;
     // XOR features and key search
-    if(!args_info.features_given && !args_info.key_given || (args_info.features_given && args_info.key_given))
+    if((!args_info.features_given && !args_info.key_given) || (args_info.features_given && args_info.key_given))
       error("QUERY requires exactly one of either -f features or -k key");
     if(args_info.features_given)
       inFile=args_info.features_arg; // query from file
@@ -887,7 +891,7 @@
 
 // This entry point is visited once per instance
 // so it is a good place to set any global state variables
-int main(const unsigned argc, char* const argv[]){
+int main(const int argc, const char* argv[]){
   SERVER_LSH_INDEX_SINGLETON = 0; // Initialize global variables
   SERVER_ADB_ROOT = 0;            // Server-side database root prefix
   SERVER_ADB_FEATURE_ROOT = 0;    // Server-side features root prefix
@@ -906,7 +910,7 @@
 
     //adb_ptr audiodb_create(char * path,long ntracks, long datadim) {
     adb_ptr audiodb_create(char * path,long datasize,long ntracks, long datadim) {
-        char *argv[12];
+        const char *argv[12];
         int argvctr=0;
         char tempstr1[200];
         char tempstr2[200];
@@ -952,7 +956,7 @@
 
 
   int audiodb_insert(adb_ptr mydb, adb_insert_ptr ins) {
-    char *argv[15];
+    const char *argv[15];
     int argvctr=0;
     int apierror=0;
 
@@ -986,18 +990,17 @@
 
   int audiodb_batchinsert(adb_ptr mydb, adb_insert_ptr ins, unsigned int size) {
 
-    char *argv[22];
+    const char *argv[22];
     int argvctr=0;
     unsigned int i=0;
-    int retval=0;
     char tempfeaturename[]="tempfeatureXXXXXX";
     char temppowername[]="temppowerXXXXXX";
     char tempkeyname[]="tempkeyXXXXXX";
     char temptimesname[]="temptimesXXXXXX";
-    int tempfeaturefd=0;
-    int temppowerfd=0;
-    int tempkeyfd=0;
-    int temptimesfd=0;
+    int tempfeaturefd = -1;
+    int temppowerfd = -1;
+    int tempkeyfd = -1;
+    int temptimesfd = -1;
 
     int flags[4]={0};
     int apierror=0;
@@ -1025,77 +1028,43 @@
 
 
     /* make four temp files */
-    tempfeaturefd=mkstemp(tempfeaturename);
-    if (tempfeaturefd !=-1){ 
+    if ((tempfeaturefd = mkstemp(tempfeaturename)) == -1)
+      goto error;
+    if ((temppowerfd = mkstemp(temppowername)) == -1)
+      goto error;
+    if ((tempkeyfd=mkstemp(tempkeyname)) == -1)
+      goto error;
+    if ((temptimesfd=mkstemp(temptimesname)) == -1)
+      goto error;
 
-        temppowerfd=mkstemp(temppowername);
-        if (temppowerfd !=-1){ 
-
-            tempkeyfd=mkstemp(tempkeyname);
-            if (tempkeyfd !=-1){ 
-
-                temptimesfd=mkstemp(temptimesname);
-                if (temptimesfd !=-1){ 
-
-                } else {
-                    retval=-1; 
-                    close(tempkeyfd);
-                    remove(tempkeyname);
-                    close(temppowerfd);
-                    remove(temppowername);
-                    close(tempfeaturefd);
-                    remove(tempfeaturename);
-                }
-
-            } else {
-                retval=-1; 
-                close(temppowerfd);
-                remove(temppowername);
-                close(tempfeaturefd);
-                remove(tempfeaturename);
-            }
-
-        } else {
-            retval=-1; 
-            close(tempfeaturefd);
-            remove(tempfeaturename);
-        } 
-
-    } else { 
-        retval=-1; 
-    }
-
-
-
-
-
-    if (retval == -1){
-        return -1;
-    }
-        
     /* Ok, so we should have a working set of files to write to */ 
     /* I'm going to assume that the same format is kept for all structs in the array */
     /* That is, each struct should be correctly formed, and contain at least a features file, because I'm just going to pass the terms along to the text files */
-    for (i=0; i<size; i++){
+    for (i = 0; i < size; i++) {
+      if (write(tempfeaturefd,ins[i].features,strlen(ins[i].features)) != (ssize_t) strlen(ins[i].features))
+	goto error;
+      if (write(tempfeaturefd,"\n",1) != 1)
+	goto error;
 
-         write(tempfeaturefd,ins[i].features,strlen(ins[i].features)); 
-         write(tempfeaturefd,"\n",1); 
-
-         if (flags[1]){
-             write(temppowerfd,ins[i].power,strlen(ins[i].power)); 
-             write(temppowerfd,"\n",1); 
-         }
-
-         if (flags[2]){
-             write(tempkeyfd,ins[i].key,strlen(ins[i].key)); 
-             write(tempkeyfd,"\n",1); 
-         }
-
-         if (flags[3]){
-             write(temptimesfd,ins[i].times,strlen(ins[i].times)); 
-             write(temptimesfd,"\n",1); 
-         }
-    } 
+      if (flags[1]) {
+	if (write(temppowerfd,ins[i].power,strlen(ins[i].power)) != (ssize_t) strlen(ins[i].power))
+	  goto error;
+	if (write(temppowerfd,"\n",1) != 1)
+	  goto error;
+      }
+      if (flags[2]) {
+	if (write(tempkeyfd,ins[i].key,strlen(ins[i].key)) != (ssize_t) strlen(ins[i].key))
+	  goto error;
+	if (write(tempkeyfd,"\n",1) != 1)
+	  goto error;
+      }
+      if (flags[3]) {
+	if (write(temptimesfd,ins[i].times,strlen(ins[i].times)) != (ssize_t) strlen(ins[i].times))
+	  goto error;
+	if (write(temptimesfd,"\n",1) != 1)
+	  goto error;
+      }
+    }
 
     argv[argvctr++]="-F";
     argv[argvctr++]=tempfeaturename;
@@ -1130,12 +1099,31 @@
 
 
     return apierror;
+
+  error:
+    if(tempfeaturefd != -1) {
+      close(tempfeaturefd);
+      remove(tempfeaturename);
+    }
+    if(temppowerfd != -1) {
+      close(temppowerfd);
+      remove(temppowername);
+    }
+    if(tempkeyfd != -1) {
+      close(tempkeyfd);
+      remove(tempkeyname);
+    }
+    if(temptimesfd != -1) {
+      close(temptimesfd);
+      remove(temptimesname);
+    }
+    return -1;
   }
 
 
   int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqr){
 
-    char *argv[32];
+    const char *argv[32];
     int argvctr=0;
     char tempstr1[200];
     char tempstr2[200];
@@ -1248,7 +1236,7 @@
       cppstatus sss;
       int apierror=0;
 
-      char * argv[5];
+      const char *argv[5];
 
       apierror=0;
       argv[0]="audioDB";
@@ -1273,9 +1261,9 @@
       return audiodb_dump_withdir(mydb,"audioDB.dump");
   }
 
-  int audiodb_dump_withdir(adb_ptr mydb, char * outputdir){
+  int audiodb_dump_withdir(adb_ptr mydb, const char *outputdir){
 
-      char * argv[7];
+      const char *argv[7];
       int argvctr=0;
       int apierror=0;
 
@@ -1285,7 +1273,7 @@
       argv[argvctr++]=mydb->dbname;
       argv[argvctr++]="--output";
       argv[argvctr++]=(char *)outputdir;
-      argv[argvctr+1]='\0';
+      argv[argvctr]='\0';
 
       audioDB::audioDB(6,argv,&apierror);
 
@@ -1294,7 +1282,7 @@
 
   int audiodb_l2norm(adb_ptr mydb){
 
-      char * argv[5];
+      const char *argv[5];
       int apierror=0;
 
       argv[0]="audioDB";
@@ -1309,7 +1297,7 @@
 
   int audiodb_power(adb_ptr mydb){
 
-      char * argv[5];
+      const char *argv[5];
       int apierror=0;
 
       argv[0]="audioDB";
--- a/audioDB.h	Wed Nov 12 10:21:06 2008 +0000
+++ b/audioDB.h	Wed Nov 12 15:40:40 2008 +0000
@@ -133,10 +133,10 @@
 // Macros
 #define O2_ACTION(a) (strcmp(command,a)==0)
 
-#define ALIGN_UP(x,w) ((x) + ((1<<w)-1) & ~((1<<w)-1))
+#define ALIGN_UP(x,w) (((x) + ((1<<w)-1)) & ~((1<<w)-1))
 #define ALIGN_DOWN(x,w) ((x) & ~((1<<w)-1))
 
-#define ALIGN_PAGE_UP(x) ((x) + (getpagesize()-1) & ~(getpagesize()-1))
+#define ALIGN_PAGE_UP(x) (((x) + (getpagesize()-1)) & ~(getpagesize()-1))
 #define ALIGN_PAGE_DOWN(x) ((x) & ~(getpagesize()-1))
 
 #define ENSURE_STRING(x) ((x) ? (x) : "")
@@ -149,6 +149,26 @@
     var = (type) tmp; \
   }
 
+#define CHECKED_READ(fd, buf, count) \
+  { size_t tmpcount = count; \
+    ssize_t tmp = read(fd, buf, tmpcount); \
+    if(tmp == -1) { \
+      error("read error", "", "read"); \
+    } else if((size_t) tmp != tmpcount) {	\
+      error("short read", ""); \
+    } \
+  }
+
+#define CHECKED_WRITE(fd, buf, count) \
+  { size_t tmpcount = count; \
+    ssize_t tmp = write(fd, buf, tmpcount); \
+    if(tmp == -1) { \
+      error("write error", "", "write"); \
+    } else if((size_t) tmp != tmpcount) {	\
+      error("short write", ""); \
+    } \
+  }
+
 #define VERB_LOG(vv, ...) \
   if(verbosity > vv) { \
     fprintf(stderr, __VA_ARGS__); \
@@ -302,6 +322,7 @@
   unsigned lisztLength;
 
   //for lib / API
+  int apierrortemp;
   unsigned UseApiError;
 
   // private methods
@@ -333,18 +354,18 @@
   void prefix_name(char** const name, const char* prefix);
 
  public:
-  audioDB(const unsigned argc, const char *const argv[]);
-  audioDB(const unsigned argc, const char *const argv[], adb__queryResponse *adbQueryResponse);
-  audioDB(const unsigned argc, const char *const argv[], adb__statusResponse *adbStatusResponse);
-  audioDB(const unsigned argc, const char *const argv[], adb__lisztResponse *adbLisztResponse);
-  audioDB(const unsigned argc, char* const argv[], int * apierror);
-  audioDB(const unsigned argc, char* const argv[], cppstatusptr stat, int * apierror);
-  audioDB(const unsigned argc, char* const argv[],adb__queryResponse *adbQueryResponse, int * apierror);
+  audioDB(const unsigned argc, const char *argv[]);
+  audioDB(const unsigned argc, const char *argv[], adb__queryResponse *adbQueryResponse);
+  audioDB(const unsigned argc, const char *argv[], adb__statusResponse *adbStatusResponse);
+  audioDB(const unsigned argc, const char *argv[], adb__lisztResponse *adbLisztResponse);
+  audioDB(const unsigned argc, const char *argv[], int * apierror);
+  audioDB(const unsigned argc, const char *argv[], cppstatusptr stat, int * apierror);
+  audioDB(const unsigned argc, const char *argv[],adb__queryResponse *adbQueryResponse, int * apierror);
 
 
   void cleanup();
   ~audioDB();
-  int processArgs(const unsigned argc, const char* const argv[]);
+  int processArgs(const unsigned argc, const char* argv[]);
   void get_lock(int fd, bool exclusive);
   void release_lock(int fd);
   void create(const char* dbName);
@@ -411,8 +432,6 @@
   // Web Services
   void startServer();
 
-  int apierrortemp;
-
   void ws_status(const char*dbName, char* hostport);
   void ws_query(const char*dbName, const char *featureFileName, const char* hostport);
   void ws_query_by_key(const char*dbName, const char *trackKey, const char* featureFileName, const char* hostport);
@@ -491,6 +510,8 @@
     exact_evaluation_queue(0),                  \
     lisztOffset(0),                             \
     lisztLength(0),                             \
+    apierrortemp(0),                            \
+    UseApiError(0),                             \
     lsh(0),					\
     lsh_in_core(false),				\
     lsh_use_u_functions(false),                 \
@@ -502,6 +523,5 @@
     lsh_param_b(0),				\
     lsh_param_ncols(0),                         \
     lsh_n_point_bits(0),                        \
-    vv(0),          \
-    apierrortemp(0)
+    vv(0)
 #endif
--- a/audioDB_API.h	Wed Nov 12 10:21:06 2008 +0000
+++ b/audioDB_API.h	Wed Nov 12 15:40:40 2008 +0000
@@ -112,6 +112,6 @@
 
 /* varoius dump formats */
 int audiodb_dump(adb_ptr mydb);
-int audiodb_dump_withdir(adb_ptr mydb, char * outputdir);
+int audiodb_dump_withdir(adb_ptr mydb, const char *outputdir);
 
 
--- a/common.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/common.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -53,15 +53,15 @@
  
 
     if(isServer) {
-    /* FIXME: I think this is leaky -- we never delete err.  actually
-       deleting it is tricky, though; it gets placed into some
-       soap-internal struct with uncertain extent... -- CSR,
-       2007-10-01 */
-    char *err = new char[256]; /* FIXME: overflows */
-    snprintf(err, 255, "%s: %s\n%s", a, b, sysFunc ? strerror(errno) : "");
-    /* FIXME: actually we could usefully do with a properly structured
-       type, so that we can throw separate faultstring and details.
-       -- CSR, 2007-10-01 */
+        /* FIXME: I think this is leaky -- we never delete err.
+           actually deleting it is tricky, though; it gets placed into
+           some soap-internal struct with uncertain extent... -- CSR,
+           2007-10-01 */
+        char *err = new char[256]; /* FIXME: overflows */
+        snprintf(err, 255, "%s: %s\n%s", a, b, sysFunc ? strerror(errno) : "");
+        /* FIXME: actually we could usefully do with a properly
+           structured type, so that we can throw separate faultstring
+           and details.  -- CSR, 2007-10-01 */
         throw(err);
     } else if (UseApiError){
         apierrortemp=-1;
--- a/create.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/create.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -78,7 +78,7 @@
     dbH->dbSize = dbH->l2normTableOffset;
   } 
 
-  write(dbfid, dbH, O2_HEADERSIZE);
+  CHECKED_WRITE(dbfid, dbH, O2_HEADERSIZE);
 
   // go to the location corresponding to the last byte
   if (lseek (dbfid, dbH->dbSize - 1, SEEK_SET) == -1)
--- a/index.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/index.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -603,11 +603,13 @@
   }
   else if(numVecsAboveThreshold)
     for( Uns32T pointID = 0 ; pointID < Nq; pointID++ )
-      if(!use_absolute_threshold || (use_absolute_threshold && (*qpp++ >= absolute_threshold)))
-	if((lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core)
+      if(!use_absolute_threshold || (use_absolute_threshold && (*qpp++ >= absolute_threshold))) {
+	if((lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) {
 	  lsh->retrieve_point((*vv)[pointID], pointID, add_point_func, (void*)this);
-	else
+        } else {
 	  lsh->serial_retrieve_point(database, (*vv)[pointID], pointID, add_point_func, (void*)this);   
+        }
+      }
 
   if(lsh_exact)
     // Perform exact distance computation on point pairs in exact_evaluation_queue
--- a/insert.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/insert.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -15,8 +15,10 @@
 }
 
 void audioDB::insert_data_vectors(off_t offset, void *buffer, size_t size) {
-  lseek(dbfid, dbH->dataOffset + offset, SEEK_SET);
-  write(dbfid, buffer, size);
+  if(lseek(dbfid, dbH->dataOffset + offset, SEEK_SET) == (off_t) -1) {
+    error("error seeking to offset", "", "lseek");
+  }
+  CHECKED_WRITE(dbfid, buffer, size);
 }
 
 void audioDB::insert(const char* dbName, const char* inFile) {
--- a/lshlib.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/lshlib.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -22,7 +22,7 @@
   return (Uns32T)log2((double)pagesz);  
 }
 
-unsigned align_up(unsigned x, unsigned w){ return ((x) + ((1<<w)-1) & ~((1<<w)-1)); }
+unsigned align_up(unsigned x, unsigned w) { return (((x) + ((1<<w)-1)) & ~((1<<w)-1)); }
 
 void H::error(const char* a, const char* b, const char *sysFunc) {
   cerr << a << ": " << b << endl;
@@ -527,15 +527,17 @@
   H::compute_hash_functions( v );
   for(Uns32T j = 0 ; j < H::L ; j++ ){
     H::generate_hash_keys( *( H::g + j ), *( H::r1 + j ), *( H::r2 + j ) ); 
-    if( bucket* bPtr = *(get_bucket(j) + get_t1()) )
+    if( bucket* bPtr = *(get_bucket(j) + get_t1()) ) {
 #ifdef LSH_LIST_HEAD_COUNTERS
-      if(bPtr->t2&LSH_CORE_ARRAY_BIT)
+      if(bPtr->t2&LSH_CORE_ARRAY_BIT) {
 	retrieve_from_core_hashtable_array((Uns32T*)(bPtr->next), qpos);
-      else
+      } else {
 	bucket_chain_point( bPtr->next, qpos);
+      }
 #else
-    bucket_chain_point( bPtr , qpos);
+      bucket_chain_point( bPtr , qpos);
 #endif
+    }
   }
 }
 
@@ -684,18 +686,19 @@
     error("Unrecognized serial file format request: ", "serialize()");
  
   // Test to see if file exists
-  if((dbfid = open (filename, O_RDONLY)) < 0)
+  if((dbfid = open (filename, O_RDONLY)) < 0) {
     // If it doesn't, then create the file (CREATE)
-    if(errno == ENOENT){
+    if(errno == ENOENT) {
       // Create the file
       std::cout << "Creating new serialized LSH database:" << filename << "...";
       std::cout.flush();
       serial_create(filename, serialFormat);
       dbIsNew=1;
-    }
-    else
+    } else {
       // The file can't be opened
       error("Can't open the file", filename, "open");
+    }
+  }
 
   // Load the on-disk header into core
   dbfid = serial_open(filename, 1); // open for write
@@ -846,17 +849,19 @@
       pe=pt+y*lshHeader->numCols;
       
       colCount=0;
-      if(bucket* bPtr = h[x][y])
-	if(merge)
+      if(bucket* bPtr = h[x][y]) {
+	if(merge) {
 #ifdef LSH_LIST_HEAD_COUNTERS
 	  serial_merge_hashtable_row_format1(pe, bPtr->next, colCount); // skip collision counter bucket
-	else
+	} else {
 	  serial_write_hashtable_row_format1(pe, bPtr->next, colCount); // skip collision counter bucket
 #else
-      serial_merge_hashtable_row_format1(pe, bPtr, colCount);
-      else
-	serial_write_hashtable_row_format1(pe, bPtr, colCount);
+          serial_merge_hashtable_row_format1(pe, bPtr, colCount);
+        } else {
+	  serial_write_hashtable_row_format1(pe, bPtr, colCount);
 #endif
+	}
+      }
       if(colCount){
 	if(colCount<minColCount)
 	  minColCount=colCount;
--- a/query.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/query.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -239,7 +239,7 @@
     }
   }
 
-  read(trkfid, *data_buffer_p, trackTable[track] * sizeof(double) * dbH->dim);
+  CHECKED_READ(trkfid, *data_buffer_p, trackTable[track] * sizeof(double) * dbH->dim);
 }
 
 // These names deserve some unpicking.  The names starting with a "q"
--- a/sample.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/sample.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -109,11 +109,15 @@
 
     /* FIXME: this seeking, reading and distance calculation should
        share more code with the query loop */
-    lseek(dbfid, dbH->dataOffset + trackOffsetTable[track1] * sizeof(double) + i1 * dbH->dim * sizeof(double), SEEK_SET);
-    read(dbfid, v1, dbH->dim * sequenceLength * sizeof(double));
+    if(lseek(dbfid, dbH->dataOffset + trackOffsetTable[track1] * sizeof(double) + i1 * dbH->dim * sizeof(double), SEEK_SET) == (off_t) -1) {
+      error("seek failure", "", "lseek");
+    }
+    CHECKED_READ(dbfid, v1, dbH->dim * sequenceLength * sizeof(double));
 
-    lseek(dbfid, dbH->dataOffset + trackOffsetTable[track2] * sizeof(double) + i2 * dbH->dim * sizeof(double), SEEK_SET);
-    read(dbfid, v2, dbH->dim * sequenceLength * sizeof(double));
+    if(lseek(dbfid, dbH->dataOffset + trackOffsetTable[track2] * sizeof(double) + i2 * dbH->dim * sizeof(double), SEEK_SET) == (off_t) -1) {
+      error("seek failure", "", "lseek");
+    }
+    CHECKED_READ(dbfid, v2, dbH->dim * sequenceLength * sizeof(double));
 
     v1norm = 0;
     v2norm = 0;
--- a/soap.cpp	Wed Nov 12 10:21:06 2008 +0000
+++ b/soap.cpp	Wed Nov 12 15:40:40 2008 +0000
@@ -143,7 +143,7 @@
 
 /* Server definitions */
 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResponse &adbStatusResponse){
-  const char *const argv[]={"./audioDB",COM_STATUS,"-d",dbName};
+  const char *argv[]={"./audioDB",COM_STATUS,"-d",dbName};
   const unsigned argc = 4;
   try {
     audioDB(argc, argv, &adbStatusResponse);
@@ -160,7 +160,7 @@
   INTSTRINGIFY(lisztOffset, lisztOffsetStr);
   INTSTRINGIFY(lisztLength, lisztLengthStr);
 
-  const char* const argv[] = {"./audioDB", COM_LISZT, "-d",dbName, "--lisztOffset", lisztOffsetStr, "--lisztLength", lisztLengthStr};
+  const char *argv[] = {"./audioDB", COM_LISZT, "-d",dbName, "--lisztOffset", lisztOffsetStr, "--lisztLength", lisztLengthStr};
   const unsigned argc = 8;
   try{
     audioDB(argc, argv, &adbLisztResponse);
@@ -283,7 +283,7 @@
   argv[argv_counter] = NULL;
 
   try {
-    audioDB(argc, (char* const*)argv, &adbQueryResponse);
+    audioDB(argc, argv, &adbQueryResponse);
     delete [] argv;
     return SOAP_OK;
   } catch (char *err) {
@@ -351,7 +351,7 @@
   
  
   try {
-    audioDB(argc, (char* const*)argv, &adbQueryResponse);
+    audioDB(argc, argv, &adbQueryResponse);
     return SOAP_OK;
   } catch (char *err) {
     soap_receiver_fault(soap, err, "");