]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix various assertion with side effects
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Nov 2012 06:45:56 +0000 (23:45 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Nov 2012 06:45:56 +0000 (23:45 -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 fcc0b45400afba95ee4e2b87679db2b8194d7f2c..ff381464152237a81eb54e1325361c68630b247a 100644 (file)
@@ -407,7 +407,8 @@ DiskdIOStrategy::SEND(diomsg *M, int mtype, int id, size_t size, off_t offset, s
     } else {
         debugs(79, DBG_IMPORTANT, "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 c8603e74882f125464ffa5f4bb5aa5d2704b9406..95bc9569fe4f973c6abc9d22fe5eceb58a316d7f 100644 (file)
@@ -360,7 +360,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 9024ebb76dafd24035dd67df48f0298c57e4958a..2fc79c2420b5bf3d8274b786e92f230eb5dc4c2a 100644 (file)
@@ -490,7 +490,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;
@@ -628,13 +629,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;