From f4800d0cfbadf9fc50dddbe2b1eb8d62548d7fe5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 14 Aug 2022 09:47:41 -0700 Subject: Reduce variable scopes as suggested by cppcheck [save.c:203]: (style) The scope of the variable 'i' can be reduced. [save.c:457]: (style) The scope of the variable 'i' can be reduced. [smproxy.c:101]: (style) The scope of the variable 'i' can be reduced. [smproxy.c:1114]: (style) The scope of the variable 'client_window' can be reduced. Signed-off-by: Alan Coopersmith --- save.c | 8 +++----- smproxy.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/save.c b/save.c index e790dc7..3d92183 100644 --- a/save.c +++ b/save.c @@ -200,8 +200,6 @@ read_counted_string(FILE *file, char **stringp) int WriteProxyFileEntry(FILE *proxyFile, WinInfo *theWindow) { - int i; - if (!write_counted_string (proxyFile, theWindow->client_id)) return 0; if (!write_counted_string (proxyFile, theWindow->class.res_name)) @@ -220,7 +218,7 @@ WriteProxyFileEntry(FILE *proxyFile, WinInfo *theWindow) { if (!write_byte (proxyFile, (char) theWindow->wm_command_count)) return 0; - for (i = 0; i < theWindow->wm_command_count; i++) + for (int i = 0; i < theWindow->wm_command_count; i++) if (!write_counted_string (proxyFile, theWindow->wm_command[i])) return 0; } @@ -454,10 +452,10 @@ LookupClientID(WinInfo *theWindow) strcmp (theWindow->class.res_class, ptr->class.res_class) == 0 && strcmp (theWindow->wm_name, ptr->wm_name) == 0) { - int i; - if (theWindow->wm_command_count == ptr->wm_command_count) { + int i; + for (i = 0; i < theWindow->wm_command_count; i++) if (strcmp (theWindow->wm_command[i], ptr->wm_command[i]) != 0) diff --git a/smproxy.c b/smproxy.c index 6e32371..fb12cbf 100644 --- a/smproxy.c +++ b/smproxy.c @@ -98,7 +98,7 @@ HasSaveYourself(Window window) { Atom *protocols; int numProtocols; - int i, found; + int found; protocols = NULL; @@ -109,9 +109,10 @@ HasSaveYourself(Window window) if (protocols != NULL) { - for (i = 0; i < numProtocols; i++) + for (int i = 0; i < numProtocols; i++) { if (protocols[i] == wmSaveYourselfAtom) found = 1; + } XFree (protocols); } @@ -240,7 +241,6 @@ FinishSaveYourself(WinInfo *winInfo, Bool has_WM_SAVEYOURSELF) { SmProp prop1, prop2, prop3, *props[3]; SmPropValue prop1val, prop2val, prop3val; - int i; if (!winInfo->got_first_save_yourself) { @@ -299,7 +299,7 @@ FinishSaveYourself(WinInfo *winInfo, Bool has_WM_SAVEYOURSELF) return; } - for (i = 0; i < winInfo->wm_command_count; i++) + for (int i = 0; i < winInfo->wm_command_count; i++) { prop1.vals[i].value = (SmPointer) winInfo->wm_command[i]; prop1.vals[i].length = strlen (winInfo->wm_command[i]); @@ -884,7 +884,7 @@ ProxySaveYourselfPhase2CB(SmcConn smcConn, SmPointer clientData) SmProp prop1, prop2, prop3, *props[3]; SmPropValue prop1val, prop2val, prop3val; char *discardCommand; - int numVals, i; + int numVals; static int first_time = 1; if (first_time) @@ -943,7 +943,7 @@ ProxySaveYourselfPhase2CB(SmcConn smcConn, SmPointer clientData) numVals = 0; - for (i = 0; i < Argc; i++) + for (int i = 0; i < Argc; i++) { if (strcmp (Argv[i], "-clientId") == 0 || strcmp (Argv[i], "-restore") == 0) @@ -1111,9 +1111,8 @@ ConnectProxyToSM(char *previous_id) static void CheckForExistingWindows(Window root) { - Window dontCare1, dontCare2, *children, client_window; + Window dontCare1, dontCare2, *children; unsigned int nchildren, i; - XCreateWindowEvent event; /* * We query the root tree for all windows created thus far. @@ -1126,7 +1125,8 @@ CheckForExistingWindows(Window root) for (i = 0; i < nchildren; i++) { - event.window = children[i]; + Window client_window; + XCreateWindowEvent event = { .window = children[i] }; HandleCreate (&event); -- cgit v1.2.3