]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix various assertion with side effects
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 29 Nov 2012 11:17:11 +0000 (04:17 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 29 Nov 2012 11:17:11 +0000 (04:17 -0700)
When compiled with high optimization and assert disabled these operations
would have disappeared. The side effects being:
* Disk I/O failure protection disabled. Allowing loops in diskd write.
* squidpurge error handling on command line parse gone. Causing segfault.
* squidpurge 'I am Alive' ticker feature cease working.

 Detected by Coverity Scan. Issues 740299, 740300, 740301, 740302, 740303

src/DiskIO/DiskDaemon/DiskdIOStrategy.cc
src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc
tools/purge/purge.cc

index 1168bfea9eb5793fad5ba774a6e20acc8b831029..0dd5f6a65e003c62286e6a479459ff7310f21a6a 100644 (file)
@@ -405,7 +405,8 @@ DiskdIOStrategy::SEND(diomsg *M, int mtype, int id, size_t size, off_t offset, s
     } else {
         debugs(79, 1, "storeDiskdSend: msgsnd: " << xstrerror());
         cbdataReferenceDone(M->callback_data);
-        assert(++send_errors < 100);
+        ++send_errors;
+        assert(send_errors < 100);
         if (shm_offset > -1)
             shm.put(shm_offset);
     }
index 19f220b44cd007900d0354a655c63c2a14433c9d..72ec72264dbc4662885e898371308eee47b3ddc9 100644 (file)
@@ -356,7 +356,8 @@ DiskThreadsDiskFile::writeDone(int rvfd, int errflag, size_t len, RefCount<Write
 
     debugs(79, 3, "DiskThreadsDiskFile::writeDone: FD " << fd << ", len " << len << ", err=" << errflag);
 
-    assert(++loop_detect < 10);
+    ++loop_detect;
+    assert(loop_detect < 10);
 
     --inProgressIOs;
 
index c6f06918f8d2c04fa86e70ee507e9da0dd793c2c..835501d24fbb28cad9f1f6c155fe9bfadc8dbc0d 100644 (file)
@@ -498,7 +498,8 @@ filelevel( const char* directory, const REList* list )
     if ( ::iamalive ) {
         static char alivelist[4][3] = { "\\\b", "|\b", "/\b", "-\b" };
         static unsigned short alivecount = 0;
-        assert( write( STDOUT_FILENO, alivelist[alivecount++ & 3], 2 ) == 2 );
+        const int write_success = write(STDOUT_FILENO, alivelist[alivecount++ & 3], 2);
+        assert(write_success == 2);
     }
 
     bool flag = true;
@@ -636,13 +637,15 @@ parseCommandline( int argc, char* argv[], REList*& head,
         case 'C':
             if ( optarg && *optarg ) {
                 if ( copydir ) xfree( (void*) copydir );
-                assert( (copydir = xstrdup(optarg)) );
+                copydir = xstrdup(optarg);
+                assert(copydir);
             }
             break;
         case 'c':
             if ( optarg && *optarg ) {
-                if ( *conffile ) xfree((void*) conffile );
-                assert( (conffile = xstrdup(optarg)) );
+                if ( *conffile ) xfree((void*) conffile);
+                conffile = xstrdup(optarg);
+                assert(conffile);
             }
             break;