Initialized variables that are conditionally set. In particular, this
construct is dangerous:
  void *p;
  if (something) p = couldReturnNull();
  if (!p) p = fallbackFunction();
---
 WPrefs.app/Appearance.c |    2 +-
 WPrefs.app/Paths.c      |    5 ++++-
 src/misc.c              |    2 +-
 src/motif.c             |    1 +
 util/getstyle.c         |    6 ++++--
 util/wmsetbg.c          |    4 ++--
 6 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c
index 106a306..9107514 100644
--- a/WPrefs.app/Appearance.c
+++ b/WPrefs.app/Appearance.c
@@ -544,7 +544,7 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * 
texture, int width, int
                int style;
                RColor rcolor2;
                int i;
-               RImage *grad, *timage;
+               RImage *grad, *timage = NULL;
                char *path;
 
                switch (toupper(type[1])) {
diff --git a/WPrefs.app/Paths.c b/WPrefs.app/Paths.c
index ca1b353..dcffd53 100644
--- a/WPrefs.app/Paths.c
+++ b/WPrefs.app/Paths.c
@@ -22,6 +22,7 @@
 
 #include "WPrefs.h"
 #include <unistd.h>
+#include <assert.h>
 
 typedef struct _Panel {
        WMBox *box;
@@ -131,6 +132,8 @@ static void browseForFile(WMWidget * w, void *data)
        _Panel *panel = (_Panel *) data;
        WMFilePanel *filePanel;
 
+       assert(w == panel->icoaB || w == panel->pixaB);
+
        filePanel = WMGetOpenPanel(WMWidgetScreen(w));
 
        WMSetFilePanelCanChooseFiles(filePanel, False);
@@ -147,7 +150,7 @@ static void browseForFile(WMWidget * w, void *data)
                                len--;
                        }
                        if (len > 0) {
-                               WMList *lPtr;
+                               WMList *lPtr = NULL;
                                int i;
 
                                if (w == panel->icoaB)
diff --git a/src/misc.c b/src/misc.c
index 7790edb..b881053 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -404,7 +404,7 @@ char *ShrinkString(WMFont * font, char *string, int width)
 
 char *FindImage(char *paths, char *file)
 {
-       char *tmp, *path;
+       char *tmp, *path = NULL;
 
        tmp = strrchr(file, ':');
        if (tmp) {
diff --git a/src/motif.c b/src/motif.c
index 3e9e5e9..c371e38 100644
--- a/src/motif.c
+++ b/src/motif.c
@@ -148,6 +148,7 @@ static int getMWMHints(Window window, MWMHints *mwmhints)
        if (!data)
                return 0;
 
+       mwmhints->flags = 0;
        if (count >= 4) {
                mwmhints->flags = data[0];
                mwmhints->functions = data[1];
diff --git a/util/getstyle.c b/util/getstyle.c
index 1023c10..577554b 100644
--- a/util/getstyle.c
+++ b/util/getstyle.c
@@ -181,7 +181,7 @@ static Bool isFontOption(char *option)
 /* XXX: is almost like WINGs/wcolodpanel.c:fetchFile() */
 void copyFile(char *dir, char *file)
 {
-       FILE *src, *dst;
+       FILE *src = NULL, *dst = NULL;
        size_t nread, nwritten, len;
        char buf[4096];
        struct stat st;
@@ -230,7 +230,9 @@ void copyFile(char *dir, char *file)
        RETRY( fclose(dst) )
 
 err:
-       RETRY( fclose(src) )
+       if (src) {
+               RETRY( fclose(src) )
+       }
        wfree(dstpath);
        return;
 }
diff --git a/util/wmsetbg.c b/util/wmsetbg.c
index cf4516f..8f7638d 100644
--- a/util/wmsetbg.c
+++ b/util/wmsetbg.c
@@ -471,7 +471,7 @@ BackgroundTexture *parseTexture(RContext * rc, char *text)
                XColor color;
                Pixmap pixmap = None;
                RImage *image = NULL;
-               int iwidth, iheight;
+               int iwidth = 0, iheight = 0;
                RColor rcolor;
 
                GETSTRORGOTO(val, tmp, 1, error);
@@ -879,7 +879,7 @@ void helperLoop(RContext * rc)
        memset(textures, 0, WORKSPACE_COUNT * sizeof(BackgroundTexture *));
 
        while (1) {
-               int workspace;
+               int workspace = -1;
 
                /* get length of message */
                if (readmsg(0, buffer, 4) < 0) {
-- 
1.7.0.4


-- 
To unsubscribe, send mail to [email protected].

Reply via email to