From d3da389f9f9b3a470bf83aa47275b7aa493d2d7b Mon Sep 17 00:00:00 2001
From: Fyren <fyrenmoo@gmail.com>
Date: Fri, 6 Mar 2015 06:27:37 +0000
Subject: [PATCH] Signed comparison warning fixes.

---
 sourcepawn/compiler/AMBuilder           |  1 -
 sourcepawn/compiler/sc.h                | 12 ++++++------
 sourcepawn/compiler/sc2.cpp             | 20 +++++++++++---------
 sourcepawn/compiler/sc3.cpp             |  3 ++-
 sourcepawn/compiler/sc4.cpp             |  3 ++-
 sourcepawn/compiler/sc5-in.scp          |  2 +-
 sourcepawn/compiler/sc5.cpp             |  2 +-
 sourcepawn/compiler/sc6.cpp             |  2 +-
 sourcepawn/compiler/sc7-in.scp          |  2 +-
 sourcepawn/compiler/sc7.cpp             |  6 +++---
 sourcepawn/compiler/scexpand.cpp        |  4 ++--
 sourcepawn/compiler/sclist.cpp          |  2 +-
 sourcepawn/include/smx/smx-v1-opcodes.h |  4 +++-
 sourcepawn/jit/file-utils.cpp           |  2 +-
 sourcepawn/jit/stack-frames.cpp         |  8 ++++----
 sourcepawn/jit/stack-frames.h           | 10 +++++-----
 16 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/sourcepawn/compiler/AMBuilder b/sourcepawn/compiler/AMBuilder
index ad687627..b716d6bd 100644
--- a/sourcepawn/compiler/AMBuilder
+++ b/sourcepawn/compiler/AMBuilder
@@ -53,7 +53,6 @@ compiler.sourcedeps += packed_includes
  
 if compiler.cc.behavior == 'gcc':
   compiler.cflags += ['-Wno-format']
-  compiler.cflags += ['-Wno-error=sign-compare']
   compiler.c_only_flags += ['-std=c99']
   if builder.target_platform == 'linux':
     compiler.postlink += ['-lm']
diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h
index 9399ed47..ae1b06e3 100644
--- a/sourcepawn/compiler/sc.h
+++ b/sourcepawn/compiler/sc.h
@@ -565,12 +565,12 @@ typedef enum s_optmark {
 
 #define suSLEEP_INSTR 0x01      /* the "sleep" instruction was used */
 
-#define FIXEDTAG     0x40000000Lu
-#define FUNCTAG      0x20000000Lu
-#define OBJECTTAG    0x10000000Lu
-#define ENUMTAG      0x08000000Lu
-#define METHODMAPTAG 0x04000000Lu
-#define STRUCTTAG    0x02000000Lu
+#define FIXEDTAG     0x40000000
+#define FUNCTAG      0x20000000
+#define OBJECTTAG    0x10000000
+#define ENUMTAG      0x08000000
+#define METHODMAPTAG 0x04000000
+#define STRUCTTAG    0x02000000
 #define TAGTYPEMASK   (FUNCTAG | OBJECTTAG | ENUMTAG | METHODMAPTAG | STRUCTTAG)
 #define TAGFLAGMASK   (FIXEDTAG | TAGTYPEMASK)
 #define TAGID(tag)    ((tag) & ~(TAGFLAGMASK))
diff --git a/sourcepawn/compiler/sc2.cpp b/sourcepawn/compiler/sc2.cpp
index ebbf3986..f2523586 100644
--- a/sourcepawn/compiler/sc2.cpp
+++ b/sourcepawn/compiler/sc2.cpp
@@ -150,7 +150,7 @@ int plungequalifiedfile(char *name)
 
   void *fp;
   char *ext;
-  int ext_idx;
+  size_t ext_idx;
 
   ext_idx=0;
   do {
@@ -258,7 +258,8 @@ static void doinclude(int silent)
 {
   char name[_MAX_PATH];
   char c;
-  int i, result;
+  size_t i;
+  int result;
 
   while (*lptr<=' ' && *lptr!='\0')         /* skip leading whitespace */
     lptr++;
@@ -276,7 +277,7 @@ static void doinclude(int silent)
     name[i++]=*lptr++;
   while (i>0 && name[i-1]<=' ')
     i--;                        /* strip trailing whitespace */
-  assert(i>=0 && i<sizeof name);
+  assert(i<sizeof name);
   name[i]='\0';                 /* zero-terminate the string */
 
   if (*lptr!=c) {               /* verify correct string termination */
@@ -1029,7 +1030,7 @@ static int command(void)
           if (*lptr=='"') {
             lptr=getstring((unsigned char*)name,sizeof name,lptr);
           } else {
-            int i;
+            size_t i;
             for (i=0; i<sizeof name && alphanum(*lptr); i++,lptr++)
               name[i]=*lptr;
             name[i]='\0';
@@ -1058,7 +1059,7 @@ static int command(void)
         } else if (strcmp(str,"rational")==0) {
           char name[sNAMEMAX+1];
           cell digits=0;
-          int i;
+          size_t i;
           /* first gather all information, start with the tag name */
           while (*lptr<=' ' && *lptr!='\0')
             lptr++;
@@ -1078,9 +1079,9 @@ static int command(void)
               lptr++;
           } /* if */
           /* add the tag (make it public) and check the values */
-          i=pc_addtag(name);
-          if (sc_rationaltag==0 || (sc_rationaltag==i && rational_digits==(int)digits)) {
-            sc_rationaltag=i;
+          int tag=pc_addtag(name);
+          if (sc_rationaltag==0 || (sc_rationaltag==tag && rational_digits==(int)digits)) {
+            sc_rationaltag=tag;
             rational_digits=(int)digits;
           } else {
             error(69);          /* rational number format already set, can only be set once */
@@ -1107,7 +1108,8 @@ static int command(void)
           sc_alignnext=TRUE;
         } else if (strcmp(str,"unused")==0) {
           char name[sNAMEMAX+1];
-          int i,comma;
+          size_t i;
+          int comma;
           symbol *sym;
           do {
             /* get the name */
diff --git a/sourcepawn/compiler/sc3.cpp b/sourcepawn/compiler/sc3.cpp
index 7b733c19..36f6c7a0 100644
--- a/sourcepawn/compiler/sc3.cpp
+++ b/sourcepawn/compiler/sc3.cpp
@@ -128,7 +128,8 @@ int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
   static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
 
   char opername[4] = "", symbolname[sNAMEMAX+1];
-  int i,swapparams,savepri,savealt;
+  size_t i;
+  int swapparams,savepri,savealt;
   int paramspassed;
   symbol *sym;
 
diff --git a/sourcepawn/compiler/sc4.cpp b/sourcepawn/compiler/sc4.cpp
index 1c0a35bf..a4154ee2 100644
--- a/sourcepawn/compiler/sc4.cpp
+++ b/sourcepawn/compiler/sc4.cpp
@@ -365,7 +365,8 @@ void alignframe(int numbytes)
 {
   #if !defined NDEBUG
     /* "numbytes" should be a power of 2 for this code to work */
-    int i,count=0;
+    size_t i;
+    int count=0;
     for (i=0; i<sizeof numbytes*8; i++)
       if (numbytes & (1 << i))
         count++;
diff --git a/sourcepawn/compiler/sc5-in.scp b/sourcepawn/compiler/sc5-in.scp
index 75025e2d..c4ab21d1 100644
--- a/sourcepawn/compiler/sc5-in.scp
+++ b/sourcepawn/compiler/sc5-in.scp
@@ -21,7 +21,7 @@
  *  Version: $Id$
  */
 
-int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
+size_t strexpand(char *dest, unsigned char *source, size_t maxlen, unsigned char pairtable[128][2]);
 
 #ifndef SCPACK
 # define SCPACK
diff --git a/sourcepawn/compiler/sc5.cpp b/sourcepawn/compiler/sc5.cpp
index 17d48618..7adebb6f 100644
--- a/sourcepawn/compiler/sc5.cpp
+++ b/sourcepawn/compiler/sc5.cpp
@@ -49,7 +49,7 @@
   #pragma warning(pop)
 #endif
 
-#define NUM_WARNINGS    (sizeof warnmsg / sizeof warnmsg[0])
+#define NUM_WARNINGS    (int)(sizeof warnmsg / sizeof warnmsg[0])
 static unsigned char warndisable[(NUM_WARNINGS + 7) / 8]; /* 8 flags in a char */
 
 static int errflag;
diff --git a/sourcepawn/compiler/sc6.cpp b/sourcepawn/compiler/sc6.cpp
index 5e73e7dd..a87106fc 100644
--- a/sourcepawn/compiler/sc6.cpp
+++ b/sourcepawn/compiler/sc6.cpp
@@ -598,7 +598,7 @@ class VerifyOpcodeSorting
  public:
   VerifyOpcodeSorting() {
     assert(opcodelist[1].name!=NULL);
-    for (int i = 2; i<(sizeof opcodelist / sizeof opcodelist[0]); i++) {
+    for (size_t i = 2; i<(sizeof opcodelist / sizeof opcodelist[0]); i++) {
       assert(opcodelist[i].name!=NULL);
       assert(stricmp(opcodelist[i].name,opcodelist[i-1].name)>0);
     } /* for */
diff --git a/sourcepawn/compiler/sc7-in.scp b/sourcepawn/compiler/sc7-in.scp
index ddbfb9b8..7cd69b54 100644
--- a/sourcepawn/compiler/sc7-in.scp
+++ b/sourcepawn/compiler/sc7-in.scp
@@ -22,7 +22,7 @@
  *  Version: $Id$
  */
 
-int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
+size_t strexpand(char *dest, unsigned char *source, size_t maxlen, unsigned char pairtable[128][2]);
 
 #define SCPACK_TERMINATOR ,     /* end each section with a comma */
 
diff --git a/sourcepawn/compiler/sc7.cpp b/sourcepawn/compiler/sc7.cpp
index 99763956..8b417eee 100644
--- a/sourcepawn/compiler/sc7.cpp
+++ b/sourcepawn/compiler/sc7.cpp
@@ -400,7 +400,7 @@ static SEQUENCE *sequences;
 
 int phopt_init(void)
 {
-  int number, i, len;
+  size_t number, i, len;
   char str[160];
 
   /* count number of sequences */
@@ -422,13 +422,13 @@ int phopt_init(void)
   for (i=0; i<number-1; i++) {
     len = strexpand(str,(unsigned char*)sequences_cmp[i].find,sizeof str,SCPACK_TABLE);
     assert(len<=sizeof str);
-    assert(len==(int)strlen(str)+1);
+    assert(len==strlen(str)+1);
     sequences[i].find=(char*)malloc(len);
     if (sequences[i].find!=NULL)
       strcpy(sequences[i].find,str);
     len = strexpand(str,(unsigned char*)sequences_cmp[i].replace,sizeof str,SCPACK_TABLE);
     assert(len<=sizeof str);
-    assert(len==(int)strlen(str)+1);
+    assert(len==strlen(str)+1);
     sequences[i].replace=(char*)malloc(len);
     if (sequences[i].replace!=NULL)
       strcpy(sequences[i].replace,str);
diff --git a/sourcepawn/compiler/scexpand.cpp b/sourcepawn/compiler/scexpand.cpp
index 09182ad6..7e6a9783 100644
--- a/sourcepawn/compiler/scexpand.cpp
+++ b/sourcepawn/compiler/scexpand.cpp
@@ -16,11 +16,11 @@
 
 #define STACKSIZE 16
 
-int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2])
+size_t strexpand(char *dest, unsigned char *source, size_t maxlen, unsigned char pairtable[128][2])
 {
   unsigned char stack[STACKSIZE];
   short c, top = 0;
-  int len;
+  size_t len;
 
   assert(maxlen > 0);
   len = 1;              /* already 1 byte for '\0' */
diff --git a/sourcepawn/compiler/sclist.cpp b/sourcepawn/compiler/sclist.cpp
index bcf7192b..a8cec15a 100644
--- a/sourcepawn/compiler/sclist.cpp
+++ b/sourcepawn/compiler/sclist.cpp
@@ -359,7 +359,7 @@ int delete_subst(char *name,int length)
 
 void delete_substtable(void)
 {
-  int i;
+  size_t i;
   delete_stringpairtable(&substpair);
   for (i=0; i<sizeof substindex/sizeof substindex[0]; i++)
     substindex[i]=NULL;
diff --git a/sourcepawn/include/smx/smx-v1-opcodes.h b/sourcepawn/include/smx/smx-v1-opcodes.h
index 9ed2601d..c50a7124 100644
--- a/sourcepawn/include/smx/smx-v1-opcodes.h
+++ b/sourcepawn/include/smx/smx-v1-opcodes.h
@@ -258,9 +258,11 @@ enum OPCODE {
 #define _(op, text) OP_##op,
   OPCODE_LIST(_)
 #undef _
-  OPCODES_TOTAL
+  OPCODES_LAST
 };
 
+#define OPCODES_TOTAL (ucell_t)OPCODES_LAST
+
 } // namespace sp
 
 #endif // _INCLUDE_SPFILE_HEADERS_v1_opcodes_H
diff --git a/sourcepawn/jit/file-utils.cpp b/sourcepawn/jit/file-utils.cpp
index 3455dd7d..f712a61e 100644
--- a/sourcepawn/jit/file-utils.cpp
+++ b/sourcepawn/jit/file-utils.cpp
@@ -38,7 +38,7 @@ FileReader::FileReader(FILE *fp)
     return;
 
   ke::AutoArray<uint8_t> bytes(new uint8_t[size]);
-  if (!bytes || fread(bytes, sizeof(uint8_t), size, fp) != size)
+  if (!bytes || fread(bytes, sizeof(uint8_t), size, fp) != (size_t)size)
     return;
 
   buffer_ = bytes.take();
diff --git a/sourcepawn/jit/stack-frames.cpp b/sourcepawn/jit/stack-frames.cpp
index c14ca03e..40206cff 100644
--- a/sourcepawn/jit/stack-frames.cpp
+++ b/sourcepawn/jit/stack-frames.cpp
@@ -21,7 +21,7 @@ using namespace ke;
 using namespace sp;
 using namespace SourcePawn;
 
-InvokeFrame::InvokeFrame(PluginContext *cx, cell_t entry_cip)
+InvokeFrame::InvokeFrame(PluginContext *cx, ucell_t entry_cip)
  : prev_(Environment::get()->top()),
    cx_(cx),
    prev_exit_frame_(Environment::get()->exit_frame()),
@@ -82,7 +82,7 @@ FrameIterator::nextInvokeFrame()
   assert(sp_stop_ >= sp_iter_);
 
   runtime_ = ivk_->cx()->runtime();
-  function_cip_ = -1;
+  function_cip_ = kInvalidCip;
   pc_ = nullptr;
   cip_ = kInvalidCip;
 
@@ -170,7 +170,7 @@ FrameIterator::findCip() const
 unsigned
 FrameIterator::LineNumber() const
 {
-  cell_t cip = findCip();
+  ucell_t cip = findCip();
   if (cip == kInvalidCip)
     return 0;
 
@@ -184,7 +184,7 @@ FrameIterator::LineNumber() const
 const char *
 FrameIterator::FilePath() const
 {
-  cell_t cip = findCip();
+  ucell_t cip = findCip();
   if (cip == kInvalidCip)
     return runtime_->image()->LookupFile(function_cip_);
 
diff --git a/sourcepawn/jit/stack-frames.h b/sourcepawn/jit/stack-frames.h
index 6269cb48..2ab3b0da 100644
--- a/sourcepawn/jit/stack-frames.h
+++ b/sourcepawn/jit/stack-frames.h
@@ -64,7 +64,7 @@ class ExitFrame
 class InvokeFrame
 {
  public:
-  InvokeFrame(PluginContext *cx, cell_t cip);
+  InvokeFrame(PluginContext *cx, ucell_t cip);
   ~InvokeFrame();
 
   InvokeFrame *prev() const {
@@ -80,7 +80,7 @@ class InvokeFrame
   const intptr_t *entry_sp() const {
     return entry_sp_;
   }
-  cell_t entry_cip() const {
+  ucell_t entry_cip() const {
     return entry_cip_;
   }
 
@@ -93,7 +93,7 @@ class InvokeFrame
   InvokeFrame *prev_;
   PluginContext *cx_;
   ExitFrame prev_exit_frame_;
-  cell_t entry_cip_;
+  ucell_t entry_cip_;
   const intptr_t *entry_sp_;
 };
 
@@ -125,8 +125,8 @@ class FrameIterator : public SourcePawn::IFrameIterator
   PluginRuntime *runtime_;
   const intptr_t *sp_iter_;
   const intptr_t *sp_stop_;
-  cell_t function_cip_;
-  mutable cell_t cip_;
+  ucell_t function_cip_;
+  mutable ucell_t cip_;
   void *pc_;
 };