From dad5f8c673f46f8a689841cdc0568fff52c5ef87 Mon Sep 17 00:00:00 2001 From: das Date: Sun, 7 Dec 2008 16:34:12 +0000 Subject: Fix potential use of uninitialized variable flagged by clang static analyzer --- generic/tkCanvPs.c | 14 +++++++------- generic/tkFileFilter.c | 4 ++-- generic/tkFont.c | 4 ++-- generic/tkListbox.c | 7 ++++--- macosx/tkMacOSXDialog.c | 7 ++++--- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/generic/tkCanvPs.c b/generic/tkCanvPs.c index 866ebba..43fc88a 100644 --- a/generic/tkCanvPs.c +++ b/generic/tkCanvPs.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvPs.c,v 1.24 2008/12/05 16:58:41 das Exp $ + * RCS: @(#) $Id: tkCanvPs.c,v 1.25 2008/12/07 16:34:12 das Exp $ */ #include "tkInt.h" @@ -1255,7 +1255,7 @@ TkPostscriptImage( * monochrome screen, use gray or monochrome mode instead. */ - if (!cdata.color && level == 2) { + if (!cdata.color && level >= 2) { level = 1; } @@ -1272,7 +1272,7 @@ TkPostscriptImage( switch (level) { case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; case 1: bytesPerLine = width; maxWidth = 60000; break; - case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; + default: bytesPerLine = 3 * width; maxWidth = 20000; break; } if (bytesPerLine > 60000) { @@ -1300,7 +1300,7 @@ TkPostscriptImage( sprintf(buffer, "%d %d 8 matrix {\n<", width, rows); Tcl_AppendResult(interp, buffer, NULL); break; - case 2: + default: sprintf(buffer, "%d %d 8 matrix {\n<", width, rows); Tcl_AppendResult(interp, buffer, NULL); break; @@ -1362,7 +1362,7 @@ TkPostscriptImage( } } break; - case 2: + default: /* * Finally, color mode. Here, just output the red, green, and * blue values directly. @@ -1388,7 +1388,7 @@ TkPostscriptImage( switch (level) { case 0: case 1: sprintf(buffer, ">\n} image\n"); break; - case 2: + default: sprintf(buffer, ">\n} false 3 colorimage\n"); break; } Tcl_AppendResult(interp, buffer, NULL); @@ -1587,7 +1587,7 @@ Tk_PostscriptPhoto( switch (colorLevel) { case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; case 1: bytesPerLine = width; maxWidth = 60000; break; - case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; + default: bytesPerLine = 3 * width; maxWidth = 20000; break; } if (bytesPerLine > 60000) { Tcl_ResetResult(interp); diff --git a/generic/tkFileFilter.c b/generic/tkFileFilter.c index 94cdbcd..4e355d4 100644 --- a/generic/tkFileFilter.c +++ b/generic/tkFileFilter.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkFileFilter.c,v 1.11 2008/04/27 22:38:56 dkf Exp $ + * RCS: @(#) $Id: tkFileFilter.c,v 1.12 2008/12/07 16:34:12 das Exp $ */ #include "tkInt.h" @@ -338,7 +338,7 @@ AddClause( globPtr->next = NULL; } } - if (ostypeCount > 0 && ostypeList != NULL) { + if (ostypeList != NULL && ostypeCount > 0) { if (macRoman == NULL) { macRoman = Tcl_GetEncoding(NULL, "macRoman"); } diff --git a/generic/tkFont.c b/generic/tkFont.c index 961feac..0b67f56 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkFont.c,v 1.50 2008/11/22 20:05:32 patthoyts Exp $ + * RCS: @(#) $Id: tkFont.c,v 1.51 2008/12/07 16:34:12 das Exp $ */ #include "tkInt.h" @@ -2675,7 +2675,7 @@ Tk_CharBbox( { TextLayout *layoutPtr; LayoutChunk *chunkPtr; - int i, x, w; + int i, x = 0, w; Tk_Font tkfont; TkFont *fontPtr; const char *end; diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 72141b8..d15246c 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkListbox.c,v 1.52 2008/11/08 22:52:29 dkf Exp $ + * RCS: @(#) $Id: tkListbox.c,v 1.53 2008/12/07 16:34:12 das Exp $ */ #include "default.h" @@ -1336,8 +1336,6 @@ ListboxYviewSubCmd( } else { type = Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count); switch (type) { - case TK_SCROLL_ERROR: - return TCL_ERROR; case TK_SCROLL_MOVETO: index = (int) (listPtr->nElements*fraction + 0.5); break; @@ -1351,6 +1349,9 @@ ListboxYviewSubCmd( case TK_SCROLL_UNITS: index = listPtr->topIndex + count; break; + case TK_SCROLL_ERROR: + default: + return TCL_ERROR; } ChangeListboxView(listPtr, index); } diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 9b1c22d..e592e3c 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.40 2008/12/07 16:32:44 das Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.41 2008/12/07 16:34:12 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -315,7 +315,7 @@ Tk_GetOpenFileObjCmd( } break; case OPEN_INITFILE: - initialFile = Tcl_GetString(objv[i + 1]); + initialFile = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); /* empty strings should be like no selection given */ if (choiceLen == 0) { initialFile = NULL; @@ -376,7 +376,8 @@ Tk_GetOpenFileObjCmd( while (filterPtr && i-- > 0) { filterPtr = filterPtr->next; } - Tcl_SetVar(interp, Tcl_GetString(typeVariablePtr), filterPtr->name, 0); + Tcl_SetVar(interp, Tcl_GetString(typeVariablePtr), filterPtr ? + filterPtr->name : "", 0); } end: -- cgit v0.12