Kaynağa Gözat

use SPtrArray handling instead of explicit delete[]

The warning message from gcc doesn't make that much sense in my reading
as there is no loop which could overflow here, but it is better to use
our SPtrArray wrapping anyway which fixes the warning as well.

warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations]
   delete[] Dsc;

Git-Dch: Ignore
Reported-By: gcc -Wunsafe-loop-optimizations
David Kalnischkies 12 yıl önce
ebeveyn
işleme
500dc07001
1 değiştirilmiş dosya ile 1 ekleme ve 10 silme
  1. 1 10
      cmdline/apt-get.cc

+ 1 - 10
cmdline/apt-get.cc

@@ -741,7 +741,7 @@ static bool DoSource(CommandLine &CmdL)
    pkgAcquire Fetcher;
    pkgAcquire Fetcher;
    Fetcher.SetLog(&Stat);
    Fetcher.SetLog(&Stat);
 
 
-   DscFile *Dsc = new DscFile[CmdL.FileSize()];
+   SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
    
    
    // insert all downloaded uris into this set to avoid downloading them
    // insert all downloaded uris into this set to avoid downloading them
    // twice
    // twice
@@ -762,7 +762,6 @@ static bool DoSource(CommandLine &CmdL)
       pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
       pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
       
       
       if (Last == 0) {
       if (Last == 0) {
-	 delete[] Dsc;
 	 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
 	 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
       }
       }
       
       
@@ -796,7 +795,6 @@ static bool DoSource(CommandLine &CmdL)
       // Back track
       // Back track
       vector<pkgSrcRecords::File> Lst;
       vector<pkgSrcRecords::File> Lst;
       if (Last->Files(Lst) == false) {
       if (Last->Files(Lst) == false) {
-	 delete[] Dsc;
 	 return false;
 	 return false;
       }
       }
 
 
@@ -859,7 +857,6 @@ static bool DoSource(CommandLine &CmdL)
    struct statvfs Buf;
    struct statvfs Buf;
    string OutputDir = ".";
    string OutputDir = ".";
    if (statvfs(OutputDir.c_str(),&Buf) != 0) {
    if (statvfs(OutputDir.c_str(),&Buf) != 0) {
-      delete[] Dsc;
       if (errno == EOVERFLOW)
       if (errno == EOVERFLOW)
 	 return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
 	 return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
 				OutputDir.c_str());
 				OutputDir.c_str());
@@ -874,7 +871,6 @@ static bool DoSource(CommandLine &CmdL)
            || unsigned(Stat.f_type) != RAMFS_MAGIC
            || unsigned(Stat.f_type) != RAMFS_MAGIC
 #endif
 #endif
            )  {
            )  {
-	 delete[] Dsc;
           return _error->Error(_("You don't have enough free space in %s"),
           return _error->Error(_("You don't have enough free space in %s"),
               OutputDir.c_str());
               OutputDir.c_str());
        }
        }
@@ -896,7 +892,6 @@ static bool DoSource(CommandLine &CmdL)
    {
    {
       for (unsigned I = 0; I != J; I++)
       for (unsigned I = 0; I != J; I++)
 	 ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
 	 ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
-      delete[] Dsc;
       return true;
       return true;
    }
    }
    
    
@@ -907,7 +902,6 @@ static bool DoSource(CommandLine &CmdL)
       for (; I != Fetcher.UriEnd(); ++I)
       for (; I != Fetcher.UriEnd(); ++I)
 	 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << 
 	 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << 
 	       I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
 	       I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
-      delete[] Dsc;
       return true;
       return true;
    }
    }
 
 
@@ -915,14 +909,12 @@ static bool DoSource(CommandLine &CmdL)
    bool Failed = false;
    bool Failed = false;
    if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
    if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
    {
    {
-      delete[] Dsc;
       return _error->Error(_("Failed to fetch some archives."));
       return _error->Error(_("Failed to fetch some archives."));
    }
    }
 
 
    if (_config->FindB("APT::Get::Download-only",false) == true)
    if (_config->FindB("APT::Get::Download-only",false) == true)
    {
    {
       c1out << _("Download complete and in download only mode") << endl;
       c1out << _("Download complete and in download only mode") << endl;
-      delete[] Dsc;
       return true;
       return true;
    }
    }
 
 
@@ -996,7 +988,6 @@ static bool DoSource(CommandLine &CmdL)
       
       
       _exit(0);
       _exit(0);
    }
    }
-   delete[] Dsc;
 
 
    // Wait for the subprocess
    // Wait for the subprocess
    int Status = 0;
    int Status = 0;