adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-devel] [patch] fix compiler warnings


From: Chris Frey
Subject: [Adonthell-devel] [patch] fix compiler warnings
Date: Sat, 4 Oct 2008 07:42:48 -0400
User-agent: Mutt/1.4.1i

Hi,

It was mentioned on IRC that compiler warnings patches would be welcome,
so here is round #1.

This is the result of compiling the latest CVS of adonthell with:

   cmake -DCMAKE_INSTALL_PREFIX=/home/adonthell-dev/rootdir \
       -DCMAKE_CXX_FLAGS="-Wall -Werror -ansi -fno-strict-aliasing -O2"

Note that -fno-strict-aliasing is required due to src/base/flat.h, which
encourages heavy duty pointer casting.  If pointers are going to be
cast like this, then you have to tell the compiler, otherwise the newer
gcc's will optimize things away that you weren't expecting, and you'll
get undefined behaviour.

I'd recommend that -fno-strict-aliasing be added to the default build.

I also ran into a conflict between python 2.4 headers on my system, and
the GNU headers, trying to battle it out, and redefine _POSIX_C_SOURCES
to their own liking.  I haven't solved this, yet.

The patch below is pretty minor, but catches some uninitialized variables
and some possible signed promotion problems.

- Chris



Subject: [PATCH] Fixed compiler warnings, using strict settings

---
 src/audio/sound.cc             |    2 +-
 src/base/diskio.h              |    2 +-
 src/base/flat.cc               |    2 +-
 src/gfx/sdl/surface_sdl.cc     |    3 +++
 src/gfx/sdlgl/screen_sdlgl.cc  |    1 +
 src/gfx/sdlgl/surface_sdlgl.cc |    4 +++-
 src/rpg/dialog.cc              |    2 +-
 src/rpg/quest.cc               |    2 +-
 src/rpg/quest_event.cc         |    2 +-
 9 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/audio/sound.cc b/src/audio/sound.cc
index f3eeefb..a4daf27 100644
--- a/src/audio/sound.cc
+++ b/src/audio/sound.cc
@@ -119,7 +119,7 @@ bool sound::handle_channel_create (void)
     if(m_channel>=0)
     {
         //The call was successful, add to m_channels list;
-        if(m_channels.size() <= m_channel)
+        if(m_channels.size() <= (unsigned int) m_channel)
             m_channels.resize(m_channel + 1);
         m_channels[m_channel] = this;
         return true;
diff --git a/src/base/diskio.h b/src/base/diskio.h
index e7f4fdf..0bcc5c0 100644
--- a/src/base/diskio.h
+++ b/src/base/diskio.h
@@ -46,7 +46,7 @@ namespace base {
             typedef enum
             {
                 GZ_FILE,
-                XML_FILE,
+                XML_FILE
             } file_format;
         
             /**
diff --git a/src/base/flat.cc b/src/base/flat.cc
index 45afb2b..d7d85b9 100644
--- a/src/base/flat.cc
+++ b/src/base/flat.cc
@@ -198,7 +198,7 @@ void flat::parse ()
     bool swap = (Buffer[0] != DATA_BYTE_ORDER);
     Buffer[0] = DATA_BYTE_ORDER;
     
-    data *first, *decoded;
+    data *first = 0, *decoded = 0;
     u_int32 pos = 1;
     Ptr = Buffer + 1;
     
diff --git a/src/gfx/sdl/surface_sdl.cc b/src/gfx/sdl/surface_sdl.cc
index fb0463b..b2b970f 100644
--- a/src/gfx/sdl/surface_sdl.cc
+++ b/src/gfx/sdl/surface_sdl.cc
@@ -209,6 +209,9 @@ namespace gfx
             case 4:
                 col = *((Uint32 *)(offset));
                 break;
+            default:
+                col = 0;
+                break;
         }
         return col;
     }
diff --git a/src/gfx/sdlgl/screen_sdlgl.cc b/src/gfx/sdlgl/screen_sdlgl.cc
index 41fd671..7bd8cab 100644
--- a/src/gfx/sdlgl/screen_sdlgl.cc
+++ b/src/gfx/sdlgl/screen_sdlgl.cc
@@ -98,6 +98,7 @@ void gfx_screen_update()
 u_int32 gfx_screen_trans_color()
 {
 // TODO
+    return 0;
 }
 
 void gfx_screen_clear()
diff --git a/src/gfx/sdlgl/surface_sdlgl.cc b/src/gfx/sdlgl/surface_sdlgl.cc
index 78d22cf..7fdee74 100644
--- a/src/gfx/sdlgl/surface_sdlgl.cc
+++ b/src/gfx/sdlgl/surface_sdlgl.cc
@@ -96,6 +96,7 @@ namespace gfx
     u_int32 surface_sdlgl::map_color(const u_int8 & r, const u_int8 & g, const 
u_int8 & b, const u_int8 & a) const
     {
        // TODO
+        return 0;
     }
 
     void surface_sdlgl::unmap_color(u_int32 col, u_int8 & r, u_int8 & g, 
u_int8 & b, u_int8 & a) const
@@ -121,6 +122,7 @@ namespace gfx
     u_int32 surface_sdlgl::get_pix (u_int16 x, u_int16 y) const
     {
        // TODO
+        return 0;
     }
 
     surface & surface_sdlgl::operator = (const surface& src)
@@ -151,7 +153,7 @@ namespace gfx
        set_height(h);
 
        u_int8 * ndata = (u_int8*) malloc(l * h * 4);
-       for (u_int32 i = 0; i < l * h; i++)
+       for (u_int32 i = 0; i < (u_int32) l * h; i++)
        {
                u_int8 red = ((u_int8*)data)[i * bytes_per_pixel];
                u_int8 green = ((u_int8*)data)[i * bytes_per_pixel + 1];
diff --git a/src/rpg/dialog.cc b/src/rpg/dialog.cc
index f40c91c..b786890 100644
--- a/src/rpg/dialog.cc
+++ b/src/rpg/dialog.cc
@@ -163,7 +163,7 @@ const rpg::dialog_line *dialog::run (const s_int32 & answer)
     {
         PyObject *speakers, *speech, *arg, *result;
         bool stop = false;
-        dialog_line *next;
+        dialog_line *next = 0;
         u_int32 size;
         
         // sanity check (answer out of bounds)
diff --git a/src/rpg/quest.cc b/src/rpg/quest.cc
index 20fb2d1..1888b25 100755
--- a/src/rpg/quest.cc
+++ b/src/rpg/quest.cc
@@ -407,7 +407,7 @@ const quest_part* quest::get_part (const std::string & path)
 // split given path
 std::vector<std::string> quest::split (const std::string & path)
 {
-    int idx, pos = 0;
+    unsigned int idx, pos = 0;
     std::vector<std::string> result;
     
     // split
diff --git a/src/rpg/quest_event.cc b/src/rpg/quest_event.cc
index 4a30c0b..eb365af 100644
--- a/src/rpg/quest_event.cc
+++ b/src/rpg/quest_event.cc
@@ -103,7 +103,7 @@ bool quest_event::get_state (base::flat& in)
 // split given path into its parts
 void quest_event::set_pattern (const std::string & pattern)
 {
-       int idx, pos = 0;
+    unsigned int idx, pos = 0;
 
     // split pattern into its levels
     while ((idx = pattern.find (".", pos)) != pattern.npos)
-- 
1.6.0.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]