]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Adjust purge sources to Squid coding standard (xmalloc, xfree etc)
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Fri, 20 Aug 2010 02:22:16 +0000 (04:22 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Fri, 20 Aug 2010 02:22:16 +0000 (04:22 +0200)
tools/purge/copyout.cc
tools/purge/hexd.cc
tools/purge/purge.cc

index 53419c80fca6d96f9a0e16c94e9a0e180741bde0..b12f11b3ab31d462b8b1f91ffdddc1db01e61c2d 100644 (file)
@@ -130,7 +130,7 @@ copy_out( size_t filesize, size_t metasize, unsigned debug,
     static const char* index = "index.html";
 
     // find hostname part after the scheme (okok, not counting port, etc.)
-    char* ptr = strstr( url, "://" );
+    const char* ptr = strstr( url, "://" );
     if ( ptr == 0 || strlen(ptr) < 4 ) return false;
 
     // create filename to store contents into
index 1756067d1a6b5ac3cc6f3c89973390690e89172e..234b81bfe213b9ce1430e061ded7357071d4998b 100644 (file)
@@ -24,7 +24,7 @@ int
 InputByByte::open(const char* fn, const size_t size )
 {
     if ( (fd = open( fn, O_RDONLY )) == -1 ) return -1;
-    if ( (buffer=(unsigned char*) malloc(size)) == 0 ) {
+    if ( (buffer=(unsigned char*) xmalloc(size)) == 0 ) {
         ::close(fd);
         return -1;
     }
@@ -54,8 +54,8 @@ InputByByte::get()
 int
 InputByByte::close()
 {
-    free((void*) buffer);
-    return close(fd);
+    xfree((void*) buffer);
+    return std::close(fd);
 }
 
 int
index 0ba6fcdd9e9ae490c3e897fa1de818b01c14e807..e0cae9610bda516ffd92bfa07106ec74197a31b8 100644 (file)
@@ -184,7 +184,7 @@ REList::REList( const char* what, bool doCase )
 REList::~REList()
 {
     if ( next ) delete next;
-    if ( data ) free((void*) data);
+    if ( data ) xfree((void*) data);
     regfree(&rexp);
 }
 
@@ -273,7 +273,7 @@ log_extended( const char* fn, int code, long size, const SquidMetaList* meta )
         }
         md5[32] = '\0'; // terminate string
     } else {
-        sprintf( md5, "%-32s", "(no_md5_data_available)" );
+        snprintf( md5, sizeof(md5), "%-32s", "(no_md5_data_available)" );
     }
 
     char timeb[64];
@@ -281,18 +281,18 @@ log_extended( const char* fn, int code, long size, const SquidMetaList* meta )
         StoreMetaStd temp;
         // make data aligned, avoid SIGBUS on RISC machines (ARGH!)
         memcpy( &temp, findings->data, sizeof(StoreMetaStd) );
-        sprintf( timeb, "%08x %08x %08x %08x %04x %5hu ",
-                 temp.timestamp, temp.lastref,
-                 temp.expires, temp.lastmod, temp.flags, temp.refcount );
+        snprintf( timeb, sizeof(timeb), "%08lx %08lx %08lx %08lx %04x %5hu ",
+                 (unsigned long)temp.timestamp, (unsigned long)temp.lastref,
+                 (unsigned long)temp.expires, (unsigned long)temp.lastmod, temp.flags, temp.refcount );
     } else if ( meta && (findings = meta->search( STORE_META_STD_LFS )) ) {
         StoreMetaStdLFS temp;
         // make data aligned, avoid SIGBUS on RISC machines (ARGH!)
         memcpy( &temp, findings->data, sizeof(StoreMetaStd) );
-        sprintf( timeb, "%08x %08x %08x %08x %04x %5hu ",
-                 temp.timestamp, temp.lastref,
-                 temp.expires, temp.lastmod, temp.flags, temp.refcount );
+        snprintf( timeb, sizeof(timeb), "%08lx %08lx %08lx %08lx %04x %5hu ",
+                 (unsigned long)temp.timestamp, (unsigned long)temp.lastref,
+                 (unsigned long)temp.expires, (unsigned long)temp.lastmod, temp.flags, temp.refcount );
     } else {
-        sprintf( timeb, "%08x %08x %08x %08x %04x %5hu ", -1, -1, -1, -1, 0, 0 );
+        snprintf( timeb, sizeof(timeb), "%08lx %08lx %08lx %08lx %04x %5hu ", (unsigned long)-1, (unsigned long)-1, (unsigned long)-1, (unsigned long)-1, 0, 0 );
     }
 
     // make sure that there is just one printf()
@@ -341,7 +341,7 @@ action( int fd, size_t metasize,
         unsigned long bufsize = strlen(url) + strlen(schablone) + 4;
         char* buffer = new char[bufsize];
 
-        sprintf( buffer, schablone, url );
+        snprintf( buffer, bufsize, schablone, url );
         int sockfd = connectTo( serverHost, serverPort, true );
         if ( sockfd == -1 ) {
             fprintf( stderr, "unable to connect to server: %s\n", strerror(errno) );
@@ -630,13 +630,13 @@ parseCommandline( int argc, char* argv[], REList*& head,
             break;
         case 'C':
             if ( optarg && *optarg ) {
-                if ( copydir ) free( (void*) copydir );
+                if ( copydir ) xfree( (void*) copydir );
                 assert( (copydir = xstrdup(optarg)) );
             }
             break;
         case 'c':
             if ( optarg && *optarg ) {
-                if ( *conffile ) free((void*) conffile );
+                if ( *conffile ) xfree((void*) conffile );
                 assert( (conffile = xstrdup(optarg)) );
             }
             break;
@@ -881,7 +881,7 @@ main( int argc, char* argv[] )
                 if ( ! dirlevel(i->base,list) )
                     fprintf( stderr, "program terminated due to error: %s",
                              strerror(errno) );
-                free((void*) i->base);
+                xfree((void*) i->base);
             }
         } else {
             // parallel mode, all cache_dir in parallel
@@ -917,7 +917,7 @@ main( int argc, char* argv[] )
                         if ( ! dirlevel(cdv[i].base,list) )
                             fprintf( stderr, "program terminated due to error: %s\n",
                                      strerror(errno) );
-                        free((void*) cdv[i].base);
+                        xfree((void*) cdv[i].base);
                         return 0;
                     } else {
                         // parent mode
@@ -941,8 +941,8 @@ main( int argc, char* argv[] )
     }
 
     // clean up
-    if ( copydir ) free( (void*) copydir );
-    free((void*) conffile);
+    if ( copydir ) xfree( (void*) copydir );
+    xfree((void*) conffile);
     delete list;
     return 0;
 }