This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rebase]: Code cleanup (was Re: [patch/rebase] Improve peflags)


On Jun 21 15:37, Corinna Vinschen wrote:
> On Jun 21 15:30, Corinna Vinschen wrote:
> > On Jun 21 09:07, Charles Wilson wrote:
> > > On 6/21/2011 8:39 AM, Jason Tishler wrote:
> > > > OK to apply?
> > > 
> > > Tab/space issues these lines (twice):
> > > +		     verbose ? old_coff_characteristics : 0,
> > 
> > What's the issue?  To use tabs is an issue?  Usually only using spaces
> > is the issue...
> 
> Talking about issues.  Shouldn't we add '-Wall -Werror' to the CFLAGS
> by default?

I created a patch which enforces these flags, as well as the -static
flags to build rebase and peflags.  Then I fixed all warnings which
occured im imagehelper.  It works for me(TM), but I would be really
glad if somebody had a good look over the changes so I didn't screw
up badly.

Thanks,
Corinna

    ChangeLog:

	* Makefile.in (CFLAGS): Override to enforce -Wall -Werror.
	(CXXFLAGS): Ditto.
	(LDFLAGS): Override to enforce static linking.

    imagehelper/ChangeLog:

	Throughout, avoid all compiler warnings.
	* Makefile.in (CFLAGS): Override to enforce -Wall -Werror.
	(CXXFLAGS): Ditto.


Index: Makefile.in
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/Makefile.in,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile.in
--- Makefile.in	21 Jun 2011 09:14:19 -0000	1.2
+++ Makefile.in	21 Jun 2011 14:55:52 -0000
@@ -57,6 +57,10 @@ ASH = @ASH@
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(srcdir)/imagehelper
 DEFS = @DEFS@ -DVERSION='"$(PACKAGE_VERSION)"' -DLIB_VERSION='"$(LIB_VERSION)"'
 
+override CFLAGS+=-Wall -Werror
+override CXXFLAGS+=-Wall -Werror
+override LDFLAGS+=-static -static-libgcc -static-libstdc++
+
 .SUFFIXES:
 .SUFFIXES: .c .cc .$(O)
 
Index: imagehelper/Makefile.in
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/Makefile.in,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile.in
--- imagehelper/Makefile.in	21 Jun 2011 08:02:59 -0000	1.3
+++ imagehelper/Makefile.in	21 Jun 2011 14:55:52 -0000
@@ -54,6 +54,9 @@ FGREP = @FGREP@
 DEFAULT_INCLUDES = -I. -I$(srcdir)
 DEFS = @DEFS@
 
+override CFLAGS+=-Wall -Werror
+override CXXFLAGS+=-Wall -Werror
+
 .SUFFIXES:
 .SUFFIXES: .c .cc .$(O)
 
Index: imagehelper/objectfile.cc
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/objectfile.cc,v
retrieving revision 1.3
diff -u -p -r1.3 objectfile.cc
--- imagehelper/objectfile.cc	21 Jun 2011 09:35:21 -0000	1.3
+++ imagehelper/objectfile.cc	21 Jun 2011 14:55:52 -0000
@@ -206,7 +206,6 @@ bool LinkedObjectFile::rebind(ObjectFile
 
   ImportDescriptor *p;
 
-  Section *edata = sections->find(".edata");
   Section *idata = sections->find(".idata");
   Section *text = sections->find(".text");
 
@@ -214,7 +213,7 @@ bool LinkedObjectFile::rebind(ObjectFile
 
   imports->reset();
 
-  while (p = imports->getNextDescriptor())
+  while ((p = imports->getNextDescriptor()) != NULL)
     {
       bool autoImportFlag;
       int *patch_address;
@@ -295,7 +294,7 @@ bool LinkedObjectFile::rebind(ObjectFile
 
   cache.reset();
 
-  while (obj = (LinkedObjectFile *)cache.getNext())
+  while ((obj = (LinkedObjectFile *)cache.getNext()) != NULL)
     {
       bp->TimeDateStamp = time(0);
       bp->OffsetModuleName = (uint)bp2 - (uint)bp_org;
@@ -317,6 +316,7 @@ bool LinkedObjectFile::rebind(ObjectFile
   bdp->VirtualAddress = (uint) bp_org - (uint)lpFileBase;
   bdp->Size = (uint) bp2 - (uint) bp_org;
 #endif
+  return true;
 }
 
 bool LinkedObjectFile::PrintDependencies(ObjectFileList &cache)
@@ -342,10 +342,8 @@ bool LinkedObjectFile::PrintDependencies
       return true;
     }
 
-  while (p = imports->getNextDescriptor())
+  while ((p = imports->getNextDescriptor()) != NULL)
     {
-      bool autoImportFlag;
-      int *patch_address;
       Section *sect = sections->find(p->Name);
       char *dllname = (char *)p->Name + sect->getAdjust();
 
@@ -387,7 +385,7 @@ bool LinkedObjectFile::unbind(void)
 
   ImportDescriptor *p;
 
-  while (p = imports->getNextDescriptor())
+  while ((p = imports->getNextDescriptor()) != NULL)
     {
 
       // set
@@ -402,6 +400,7 @@ bool LinkedObjectFile::unbind(void)
   // set data directory entry
   bdp->VirtualAddress = 0;
   bdp->Size = 0;
+  return true;
 }
 
 
Index: imagehelper/objectfilelist.cc
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/objectfilelist.cc,v
retrieving revision 1.2
diff -u -p -r1.2 objectfilelist.cc
--- imagehelper/objectfilelist.cc	20 Jun 2011 23:54:16 -0000	1.2
+++ imagehelper/objectfilelist.cc	21 Jun 2011 14:55:52 -0000
@@ -60,7 +60,7 @@ ObjectFile *ObjectFileList::get
   {
     ObjectFile *p;
     reset();
-    while (p = getNext())
+    while ((p = getNext()) != NULL)
       {
         if (strstr(FileName,p->getFileName()))
           return p;
@@ -72,7 +72,7 @@ ObjectFileList::~ObjectFileList()
 {
   ObjectFile *p;
   reset();
-  while (p = getNext())
+  while ((p = getNext()) != NULL)
     delete p;
 }
 
Index: imagehelper/sections.cc
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/sections.cc,v
retrieving revision 1.2
diff -u -p -r1.2 sections.cc
--- imagehelper/sections.cc	20 Jun 2011 23:26:26 -0000	1.2
+++ imagehelper/sections.cc	21 Jun 2011 14:55:52 -0000
@@ -186,7 +186,7 @@ void Exports::dump(char *title)
   else
     {
       reset();
-      while (p = getNext())
+      while ((p = getNext()) != NULL)
         {
           std::cout << "\t" << p << std::endl;
         }
@@ -238,7 +238,7 @@ void Imports::dump(char *title)
   std::cout << "imports" << std::endl;
 
   reset();
-  while (p = getNextDescriptor())
+  while ((p = getNextDescriptor()) != NULL)
     {
       std::cout << p->Name + adjust << std::endl;
       std::cout << "vma:           Hint     Time      Forward  DLL       First" << std::endl;
@@ -287,7 +287,7 @@ bool Relocations::check(void)
   if (debug)
     std::cerr << "debug: checking relocations .... " << std::endl;
 
-  for (; (char *)&relocp->SizeOfBlock < (char *)relocs + size && relocp->SizeOfBlock != 0; ((char *&)relocp) += relocp->SizeOfBlock)
+  for (; &relocp->SizeOfBlock < (PDWORD) ((char *)relocs + size) && relocp->SizeOfBlock != 0; relocp = (PIMAGE_BASE_RELOCATION) ((char *)relocp + relocp->SizeOfBlock))
     {
       int NumOfRelocs = (relocp->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof (WORD);
       int va = relocp->VirtualAddress;
@@ -330,11 +330,9 @@ bool Relocations::fix(void)
   if (debug)
     std::cerr << "warning: fixing bad relocations .... ";
 
-  for (; (char *)&relocp->SizeOfBlock < (char *)relocs + size && relocp->SizeOfBlock != 0; ((char *&)relocp) += relocp->SizeOfBlock)
+  for (; &relocp->SizeOfBlock < (PDWORD) ((char *)relocs + size) && relocp->SizeOfBlock != 0; relocp = (PIMAGE_BASE_RELOCATION) ((char *)relocp + relocp->SizeOfBlock))
     {
-      int NumOfRelocs = (relocp->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof (WORD);
       int va = relocp->VirtualAddress;
-      PWORD p = (PWORD)((unsigned int )relocp + sizeof(IMAGE_BASE_RELOCATION));
 
       cursec = sections->find(va);
       if (!cursec)
@@ -365,7 +363,7 @@ bool Relocations::relocate(int differenc
   if (!relocs)
     return false;
 
-  for (; (char *)&relocp->SizeOfBlock < (char *)relocs + size && relocp->SizeOfBlock != 0; ((char *&)relocp) += relocp->SizeOfBlock)
+  for (; &relocp->SizeOfBlock < (PDWORD) ((char *)relocs + size) && relocp->SizeOfBlock != 0; relocp = (PIMAGE_BASE_RELOCATION) ((char *)relocp + relocp->SizeOfBlock))
     {
       int NumOfRelocs = (relocp->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof (WORD);
       int va = relocp->VirtualAddress;
Index: imagehelper/sections.h
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/sections.h,v
retrieving revision 1.2
diff -u -p -r1.2 sections.h
--- imagehelper/sections.h	20 Jun 2011 23:26:26 -0000	1.2
+++ imagehelper/sections.h	21 Jun 2011 14:55:52 -0000
@@ -162,7 +162,7 @@ class Exports : SectionBase
   private:
     ExportDirectory *exports;
     DataDirectory *header;
-    int iterator;
+    DWORD iterator;
     //  int adjust;
 
   };

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]