From 6ded4c0487220253a2cb2fefc4983ff31e486dd4 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Thu, 29 Feb 2024 16:45:23 -0500 Subject: cppcheck scope and assignment warnings --- src/AsciiSink.c | 13 ++++++------- src/List.c | 3 ++- src/Paned.c | 4 ++-- src/Pixmap.c | 7 ++++--- src/StripChart.c | 4 ++-- src/TextAction.c | 25 +++++++++++++++---------- src/TextSrc.c | 3 ++- src/Toggle.c | 3 ++- src/Tree.c | 5 ++--- src/XawIm.c | 26 +++++++++++++++++--------- 10 files changed, 54 insertions(+), 39 deletions(-) diff --git a/src/AsciiSink.c b/src/AsciiSink.c index 5756563..3a12c75 100644 --- a/src/AsciiSink.c +++ b/src/AsciiSink.c @@ -297,12 +297,12 @@ GetTextWidth(TextWidget ctx, int current_width, XFontStruct *font, XawTextPosition from, int length) { int width = 0; - XawTextBlock block; - XawTextPosition pos = from; - int i; while (length > 0) { - pos = XawTextSourceRead(ctx->text.source, from, &block, length); + int i; + XawTextBlock block; + XawTextPosition pos = XawTextSourceRead(ctx->text.source, from, &block, length); + length = (int)(length - (pos - from)); from = pos; for (i = 0; i < block.length; i++) @@ -438,7 +438,7 @@ AsciiPreparePaint(Widget w, int y, int line, TextWidget ctx = (TextWidget)XtParent(w); AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; - XawTextPosition left, right, pos, pos2, tmp, length; + XawTextPosition left, right, pos, tmp, length; XawTextAnchor *anchor; XawTextEntity *entity; XawTextProperty *property; @@ -573,9 +573,8 @@ AsciiPreparePaint(Widget w, int y, int line, paint->length = 0; segment.x1 = x; - pos2 = tmp; while (length > 0) { - pos2 = XawTextSourceRead(ctx->text.source, tmp, &block, (int)length); + XawTextPosition pos2 = XawTextSourceRead(ctx->text.source, tmp, &block, (int)length); length = pos - pos2; tmp = pos2; for (i = 0; i < block.length; i++) { diff --git a/src/List.c b/src/List.c index 1e2d3b2..8b7e7c0 100644 --- a/src/List.c +++ b/src/List.c @@ -359,7 +359,6 @@ static void CalculatedValues(Widget w) { ListWidget lw = (ListWidget)w; - int i; /* If list is NULL then the list will just be the name of the widget */ if (lw->list.list == NULL) { @@ -374,6 +373,8 @@ CalculatedValues(Widget w) /* Get column width */ if (LongestFree(lw)) { + int i; + lw->list.longest = 0; /* so it will accumulate real longest below */ for (i = 0 ; i < lw->list.nitems; i++) { diff --git a/src/Paned.c b/src/Paned.c index b8bfdb0..59ce1a8 100644 --- a/src/Paned.c +++ b/src/Paned.c @@ -912,7 +912,7 @@ static void _DrawInternalBorders(PanedWidget pw, GC gc) { Widget *childP; - int on_loc, off_loc; + int off_loc; unsigned int on_size, off_size; /* @@ -927,7 +927,7 @@ _DrawInternalBorders(PanedWidget pw, GC gc) on_size = (unsigned int)pw->paned.internal_bw; ForAllPanes(pw, childP) { - on_loc = IsVert(pw) ? XtY(*childP) : XtX(*childP); + int on_loc = IsVert(pw) ? XtY(*childP) : XtX(*childP); on_loc -= (int)on_size; _DrawRect(pw, gc, on_loc, off_loc, on_size, off_size); diff --git a/src/Pixmap.c b/src/Pixmap.c index b076cfb..0083b8c 100644 --- a/src/Pixmap.c +++ b/src/Pixmap.c @@ -469,14 +469,15 @@ _XawFindCache(XawCache *xaw, static XawCache * _XawGetCache(XawCache *xaw, Screen *screen, Colormap colormap, int depth) { - XawCache *s_cache, *c_cache, *d_cache, *cache, *pcache; + XawCache *cache; cache = _XawFindCache(xaw, screen, colormap, depth, FIND_ALL); if (!cache) { - s_cache = _XawFindCache(xaw, - screen, colormap, depth, FIND_SCREEN); + XawCache *c_cache, *d_cache, *pcache; + XawCache *s_cache = _XawFindCache(xaw, + screen, colormap, depth, FIND_SCREEN); if (!s_cache) { pcache = (XawCache *)XtMalloc(sizeof(XawCache)); diff --git a/src/StripChart.c b/src/StripChart.c index 6c4be57..a710337 100644 --- a/src/StripChart.c +++ b/src/StripChart.c @@ -318,7 +318,7 @@ static void draw_it(XtPointer client_data, XtIntervalId *id _X_UNUSED) { StripChartWidget w = (StripChartWidget)client_data; - double value; + double value = 0.0; if (w->strip_chart.update > 0) w->strip_chart.interval_id = @@ -388,7 +388,6 @@ repaint_window(StripChartWidget w, int left, int width) int next = w->strip_chart.interval; int scale = w->strip_chart.scale; int scalewidth = 0; - int i; /* Compute the minimum scale required to graph the data, but don't go lower than min_scale */ @@ -410,6 +409,7 @@ repaint_window(StripChartWidget w, int left, int width) } if (XtIsRealized((Widget)w)) { + int i; Display *dpy = XtDisplay(w); Window win = XtWindow(w); diff --git a/src/TextAction.c b/src/TextAction.c index c3c70f6..01ec48c 100644 --- a/src/TextAction.c +++ b/src/TextAction.c @@ -3531,15 +3531,16 @@ StripOutOldCRs(TextWidget ctx, XawTextPosition from, XawTextPosition to, Widget src = ctx->text.source; XawTextBlock text; char *buf; - static wchar_t wc_two_spaces[3]; int idx; /* Initialize our TextBlock with two spaces. */ text.firstPos = 0; text.format = (unsigned long)_XawTextFormat(ctx); - if (text.format == XawFmt8Bit) - text.ptr= (char*)" "; - else { + if (text.format == XawFmt8Bit) { + text.ptr= (char*)" "; + } else { + static wchar_t wc_two_spaces[3]; + wc_two_spaces[0] = _Xaw_atowc(XawSP); wc_two_spaces[1] = _Xaw_atowc(XawSP); wc_two_spaces[2] = 0; @@ -3635,19 +3636,19 @@ static void InsertNewCRs(TextWidget ctx, XawTextPosition from, XawTextPosition to, XawTextPosition *pos, int num_pos) { - XawTextPosition startPos, endPos, space, eol; + XawTextPosition startPos; XawTextBlock text; - int i, width, height, len, wwidth, idx; - char *buf; - static wchar_t wide_CR[2]; + int i, width, height, wwidth, idx; text.firstPos = 0; text.length = 1; text.format = (unsigned long)_XawTextFormat(ctx); - if (text.format == XawFmt8Bit) + if (text.format == XawFmt8Bit) { text.ptr = (char*)"\n"; - else { + } else { + static wchar_t wide_CR[2]; + wide_CR[0] = _Xaw_atowc(XawLF); wide_CR[1] = 0; text.ptr = (char*)wide_CR; @@ -3666,6 +3667,10 @@ InsertNewCRs(TextWidget ctx, XawTextPosition from, XawTextPosition to, /* CONSTCOND */ while (TRUE) { + int len; + char *buf; + XawTextPosition endPos, space, eol; + XawTextSinkFindPosition(ctx->text.sink, startPos, (int)ctx->text.r_margin.left, wwidth, True, &eol, &width, &height); diff --git a/src/TextSrc.c b/src/TextSrc.c index 7b44717..0138e2a 100644 --- a/src/TextSrc.c +++ b/src/TextSrc.c @@ -1358,7 +1358,6 @@ static void UndoGC(XawTextUndo *undo) { XawTextUndoList *head = undo->head, *redo = head->redo; - unsigned i; if (head == undo->pointer || head == undo->end_mark || undo->l_no_change == NULL @@ -1370,6 +1369,8 @@ UndoGC(XawTextUndo *undo) --head->left->refcount; if (--head->right->refcount == 0) { + unsigned i; + for (i = 0; i < undo->num_undo; i+= 2) if (head->left == undo->undo[i] || head->left == undo->undo[i+1]) { if (head->left == undo->undo[i+1]) { diff --git a/src/Toggle.c b/src/Toggle.c index 8fc8960..2810890 100644 --- a/src/Toggle.c +++ b/src/Toggle.c @@ -615,12 +615,13 @@ XawToggleSetCurrent(Widget radio_group, XtPointer radio_data) void XawToggleUnsetCurrent(Widget radio_group) { - ToggleWidgetClass cclass; ToggleWidget local_tog = (ToggleWidget)radio_group; /* Special Case no radio group */ if (local_tog->command.set) { + ToggleWidgetClass cclass; + cclass = (ToggleWidgetClass)local_tog->core.widget_class; cclass->toggle_class.Unset(radio_group, NULL, NULL, NULL); Notify(radio_group, NULL, NULL, NULL); diff --git a/src/Tree.c b/src/Tree.c index d8859aa..9be7a24 100644 --- a/src/Tree.c +++ b/src/Tree.c @@ -834,7 +834,6 @@ static void arrange_subtree(TreeWidget tree, Widget w, int depth, int x, int y) { TreeConstraints tc = TREE_CONSTRAINT(w); /* info attached to all kids */ - TreeConstraints firstcc, lastcc; int newx, newy; Bool horiz = IsHorizontal (tree); Widget child = NULL; @@ -906,8 +905,8 @@ arrange_subtree(TreeWidget tree, Widget w, int depth, int x, int y) */ if (relayout) { Position adjusted; - firstcc = TREE_CONSTRAINT (tc->tree.children[0]); - lastcc = TREE_CONSTRAINT (child); + TreeConstraints firstcc = TREE_CONSTRAINT (tc->tree.children[0]); + TreeConstraints lastcc = TREE_CONSTRAINT (child); /* Adjustments are disallowed if they result in a position above * or to the left of the originally requested position, because diff --git a/src/XawIm.c b/src/XawIm.c index ebc5ede..81d32df 100644 --- a/src/XawIm.c +++ b/src/XawIm.c @@ -264,18 +264,19 @@ GetInputStyleOfIC(XawVendorShellExtPart *ve) static void ConfigureCB(Widget w, XtPointer closure _X_UNUSED, XEvent *event, Boolean *unused _X_UNUSED) { - XawIcTableList p; XawVendorShellExtPart *ve; VendorShellWidget vw; - XVaNestedList pe_attr; - XRectangle pe_area; - XawTextMargin *margin; if (event->type != ConfigureNotify) return; if ((vw = SearchVendorShell(w)) == NULL) return; if ((ve = GetExtPart(vw)) != NULL) { + XawIcTableList p; + XVaNestedList pe_attr; + XRectangle pe_area; + XawTextMargin *margin; + if (IsSharedIC(ve)) return; if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) || @@ -450,7 +451,7 @@ OpenIM(XawVendorShellExtPart *ve) { int i; _Xconst char *s, *ns, *end; - char *p, *pbuf, buf[32]; + char *p, buf[32]; XIM xim = NULL; XIMStyles *xim_styles; XIMStyle input_style = 0; @@ -462,6 +463,8 @@ OpenIM(XawVendorShellExtPart *ve) if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p) xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL); } else { + char *pbuf; + /* no fragment can be longer than the whole string */ Cardinal len = (Cardinal)strlen (ve->im.input_method) + 5; @@ -791,7 +794,6 @@ CreateIC(Widget w, XawVendorShellExtPart *ve) XPointer ic_a[20], pe_a[20], st_a[20]; Dimension height = 0; int ic_cnt = 0, pe_cnt = 0, st_cnt = 0; - XawTextMargin *margin; if (!XtIsRealized(w)) return; if (((ve->im.xim == NULL) || (p = GetIcTableShared(w, ve)) == NULL) || @@ -839,6 +841,7 @@ CreateIC(Widget w, XawVendorShellExtPart *ve) st_a[st_cnt] = (XPointer) p->line_spacing; st_cnt++; } } + if (p->input_style & XIMPreeditArea) { pe_area.x = 0; pe_area.y = (short)(ve->parent->core.height - height); @@ -847,7 +850,10 @@ CreateIC(Widget w, XawVendorShellExtPart *ve) pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++; pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++; } + if (p->input_style & XIMPreeditPosition) { + XawTextMargin *margin; + pe_area.x = 0; pe_area.y = 0; pe_area.width = w->core.width; @@ -1085,13 +1091,13 @@ CurrentSharedIcTable(XawVendorShellExtPart *ve) static void SetICFocus(Widget w, XawVendorShellExtPart *ve) { - XawIcTableList p, pp; + XawIcTableList p; if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) || (p->xic == NULL)) return; if (IsSharedIC(ve)) { - pp = CurrentSharedIcTable(ve); + XawIcTableList pp = CurrentSharedIcTable(ve); if (pp == NULL || pp->widget != w) { SharedICChangeFocusWindow(w, ve, p); } @@ -1232,10 +1238,12 @@ UnsetFocus(Widget inwidg) { XawVendorShellExtPart *ve; VendorShellWidget vw; - XawIcTableList p; if ((vw = SearchVendorShell(inwidg)) == NULL) return; + if ((ve = GetExtPart(vw)) != NULL) { + XawIcTableList p; + if ((p = GetIcTableShared(inwidg, ve)) == NULL) return; if (p->flg & CIICFocus) { p->flg &= (unsigned long)(~CIICFocus); -- cgit v1.2.3