[devel] [PATCH for apt v2 02/21] Use correct types and type specifiers

Aleksei Nikiforov darktemplar на altlinux.org
Чт Дек 12 12:57:11 MSK 2019


Found via cppcheck:
(warning) %li in format string (no. 1) requires 'long'
but the argument type is 'unsigned long'.

(warning) %llu in format string (no. 1) requires 'unsigned long long'
but the argument type is 'signed long long'.

And other similar warnings
---
 apt/apt-pkg/contrib/cdromutl.cc | 4 ++--
 apt/apt-pkg/contrib/strutl.cc   | 8 ++++----
 apt/cmdline/acqprogress.cc      | 4 ++--
 apt/methods/connect.cc          | 4 ++--
 apt/methods/http.cc             | 9 +++------
 apt/methods/http.h              | 2 +-
 6 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/apt/apt-pkg/contrib/cdromutl.cc b/apt/apt-pkg/contrib/cdromutl.cc
index 6101145..139be84 100644
--- a/apt/apt-pkg/contrib/cdromutl.cc
+++ b/apt/apt-pkg/contrib/cdromutl.cc
@@ -232,8 +232,8 @@ bool IdentCdrom(const string &CD,string &Res,unsigned int Version)
 	 return _error->Errno("statfs",_("Failed to stat the cdrom"));
       
       // We use a kilobyte block size to advoid overflow
-      sprintf(S,"%llu %llu",(long long)(Buf.f_blocks*(Buf.f_bsize/1024)),
-	      (long long)(Buf.f_bfree*(Buf.f_bsize/1024)));
+      sprintf(S,"%llu %llu",(unsigned long long)(Buf.f_blocks*(Buf.f_bsize/1024)),
+	      (unsigned long long)(Buf.f_bfree*(Buf.f_bsize/1024)));
       Hash.Add(S);
       sprintf(S,"-%u",Version);
    }
diff --git a/apt/apt-pkg/contrib/strutl.cc b/apt/apt-pkg/contrib/strutl.cc
index 6131d47..bde4ef5 100644
--- a/apt/apt-pkg/contrib/strutl.cc
+++ b/apt/apt-pkg/contrib/strutl.cc
@@ -292,23 +292,23 @@ string TimeToStr(unsigned long Sec)
    {
       if (Sec > 60*60*24)
       {
-	 sprintf(S,"%lid %lih%lim%lis",Sec/60/60/24,(Sec/60/60) % 24,(Sec/60) % 60,Sec % 60);
+	 sprintf(S,"%lud %luh%lum%lus",Sec/60/60/24,(Sec/60/60) % 24,(Sec/60) % 60,Sec % 60);
 	 break;
       }
       
       if (Sec > 60*60)
       {
-	 sprintf(S,"%lih%lim%lis",Sec/60/60,(Sec/60) % 60,Sec % 60);
+	 sprintf(S,"%luh%lum%lus",Sec/60/60,(Sec/60) % 60,Sec % 60);
 	 break;
       }
       
       if (Sec > 60)
       {
-	 sprintf(S,"%lim%lis",Sec/60,Sec % 60);
+	 sprintf(S,"%lum%lus",Sec/60,Sec % 60);
 	 break;
       }
       
-      sprintf(S,"%lis",Sec);
+      sprintf(S,"%lus",Sec);
       break;
    }
    
diff --git a/apt/cmdline/acqprogress.cc b/apt/cmdline/acqprogress.cc
index 8fa9420..ecf9c2e 100644
--- a/apt/cmdline/acqprogress.cc
+++ b/apt/cmdline/acqprogress.cc
@@ -215,10 +215,10 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner)
       {
 	 if (Mode == Short)
 	    snprintf(S,End-S," %lu%%",
-		     long(double(I->CurrentSize*100.0)/double(I->TotalSize)));
+		     (unsigned long) (double(I->CurrentSize*100.0)/double(I->TotalSize)));
 	 else
 	    snprintf(S,End-S,"/%sB %lu%%",SizeToStr(I->TotalSize).c_str(),
-		     long(double(I->CurrentSize*100.0)/double(I->TotalSize)));
+		     (unsigned long) (double(I->CurrentSize*100.0)/double(I->TotalSize)));
       }      
       S += strlen(S);
       snprintf(S,End-S,"]");
diff --git a/apt/methods/connect.cc b/apt/methods/connect.cc
index f086a7e..a25d6b4 100644
--- a/apt/methods/connect.cc
+++ b/apt/methods/connect.cc
@@ -162,7 +162,7 @@ bool Connect(const string &Host,int Port,const char *Service,int DefPort,std::un
    // Convert the port name/number
    char ServStr[300];
    if (Port != 0)
-      snprintf(ServStr,sizeof(ServStr),"%u",Port);
+      snprintf(ServStr,sizeof(ServStr),"%u",(unsigned) Port);
    else
       snprintf(ServStr,sizeof(ServStr),"%s",Service);
    
@@ -198,7 +198,7 @@ bool Connect(const string &Host,int Port,const char *Service,int DefPort,std::un
 	    {
 	       if (DefPort != 0)
 	       {
-		  snprintf(ServStr,sizeof(ServStr),"%u",DefPort);
+		  snprintf(ServStr,sizeof(ServStr),"%u",(unsigned) DefPort);
 		  DefPort = 0;
 		  continue;
 	       }
diff --git a/apt/methods/http.cc b/apt/methods/http.cc
index da3e646..6d9a642 100644
--- a/apt/methods/http.cc
+++ b/apt/methods/http.cc
@@ -588,7 +588,7 @@ bool ServerState::HeaderLine(const string &Line)
       
       if (sscanf(Val.c_str(),"bytes %llu-%*u/%llu",&StartPos,&Size) != 2)
 	 return _error->Error(_("The http server sent an invalid Content-Range header"));
-      if ((unsigned long long)StartPos > Size)
+      if (StartPos > Size)
 	 return _error->Error(_("This http server has broken range support"));
       return true;
    }
@@ -1016,11 +1016,8 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
    FailTime = Srv->Date;
       
    // Set the expected size
-   if (Srv->StartPos >= 0)
-   {
-      Res.ResumePoint = Srv->StartPos;
-      ftruncate(File->Fd(),Srv->StartPos);
-   }
+   Res.ResumePoint = Srv->StartPos;
+   ftruncate(File->Fd(),Srv->StartPos);
       
    // Set the start point
    lseek(File->Fd(),0,SEEK_END);
diff --git a/apt/methods/http.h b/apt/methods/http.h
index b5c2d68..3b50e73 100644
--- a/apt/methods/http.h
+++ b/apt/methods/http.h
@@ -87,7 +87,7 @@ struct ServerState
    
    // These are some statistics from the last parsed header lines
    unsigned long long Size;
-   signed long long StartPos;
+   unsigned long long StartPos;
    time_t Date;
    bool HaveContent;
    enum {Chunked,Stream,Closes} Encoding;
-- 
2.24.1



Подробная информация о списке рассылки Devel