[CppCheck] Fix some shadowing variables.

This commit is contained in:
Dave Davenport 2021-08-21 01:08:40 +02:00
parent ff924ca01c
commit c64565e877
7 changed files with 119 additions and 108 deletions

View File

@ -353,14 +353,14 @@ static void exec_cmd_entry(DRunModeEntry *e, const char *path) {
if (e->key_file == NULL) {
GKeyFile *kf = g_key_file_new();
GError *error = NULL;
gboolean res = g_key_file_load_from_file(kf, e->path, 0, &error);
GError *key_error = NULL;
gboolean res = g_key_file_load_from_file(kf, e->path, 0, &key_error);
if (res) {
e->key_file = kf;
} else {
g_warning("[%s] [%s] Failed to parse desktop file because: %s.",
e->app_id, e->path, error->message);
g_error_free(error);
e->app_id, e->path, key_error->message);
g_error_free(key_error);
g_key_file_free(kf);
return;
@ -395,10 +395,10 @@ static void exec_cmd_entry(DRunModeEntry *e, const char *path) {
gboolean terminal =
g_key_file_get_boolean(e->key_file, e->action, "Terminal", NULL);
if (helper_execute_command(exec_path, fp, terminal, sn ? &context : NULL)) {
char *path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL);
char *drun_cach_path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL);
// Store it based on the unique identifiers (desktop_id).
history_set(path, e->desktop_id);
g_free(path);
history_set(drun_cach_path, e->desktop_id);
g_free(drun_cach_path);
}
g_free(wmclass);
g_free(exec_path);

View File

@ -296,9 +296,9 @@ static RunEntry *get_apps(unsigned int *length) {
continue;
}
if (is_homedir) {
gchar *fpath = g_build_filename(dirname, dent->d_name, NULL);
gboolean b = g_file_test(fpath, G_FILE_TEST_IS_EXECUTABLE);
g_free(fpath);
gchar *full_path = g_build_filename(dirname, dent->d_name, NULL);
gboolean b = g_file_test(full_path, G_FILE_TEST_IS_EXECUTABLE);
g_free(full_path);
if (!b) {
continue;
}

View File

@ -201,20 +201,20 @@ static SshEntry *read_known_hosts_file(const char *path, SshEntry *retv,
int port = 0;
if (start[0] == '[') {
start++;
char *end = strchr(start, ']');
if (end[1] == ':') {
*end = '\0';
char *strend = strchr(start, ']');
if (strend[1] == ':') {
*strend = '\0';
errno = 0;
gchar *endptr = NULL;
gint64 number = g_ascii_strtoll(&(end[2]), &endptr, 10);
gint64 number = g_ascii_strtoll(&(strend[2]), &endptr, 10);
if (errno != 0) {
g_warning("Failed to parse port number: %s.", &(end[2]));
} else if (endptr == &(end[2])) {
g_warning("Failed to parse port number: %s.", &(strend[2]));
} else if (endptr == &(strend[2])) {
g_warning("Failed to parse port number: %s, invalid number.",
&(end[2]));
&(strend[2]));
} else if (number < 0 || number > 65535) {
g_warning("Failed to parse port number: %s, out of range.",
&(end[2]));
&(strend[2]));
} else {
port = number;
}
@ -499,15 +499,16 @@ static SshEntry *get_ssh(SSHModePrivateData *pd, unsigned int *length) {
parse_ssh_config_file(pd, path, &retv, length, num_favorites);
if (config.parse_known_hosts == TRUE) {
char *path =
char *known_hosts_path =
g_build_filename(g_get_home_dir(), ".ssh", "known_hosts", NULL);
retv = read_known_hosts_file(path, retv, length);
g_free(path);
retv = read_known_hosts_file(known_hosts_path, retv, length);
g_free(known_hosts_path);
for (GList *iter = g_list_first(pd->user_known_hosts); iter;
iter = g_list_next(iter)) {
char *path = rofi_expand_path((const char *)iter->data);
retv = read_known_hosts_file((const char *)path, retv, length);
g_free(path);
char *user_known_hosts_path = rofi_expand_path((const char *)iter->data);
retv = read_known_hosts_file((const char *)user_known_hosts_path, retv,
length);
g_free(user_known_hosts_path);
}
}
if (config.parse_hosts == TRUE) {

View File

@ -538,90 +538,97 @@ static void _window_mode_load_data(Mode *sw, unsigned int cd) {
// we're working...
pd->ids = winlist_new();
xcb_get_property_cookie_t c =
xcb_get_property_cookie_t prop_cookie =
xcb_ewmh_get_desktop_names(&xcb->ewmh, xcb->screen_nbr);
xcb_ewmh_get_utf8_strings_reply_t names;
int has_names = FALSE;
if (xcb_ewmh_get_desktop_names_reply(&xcb->ewmh, c, &names, NULL)) {
if (xcb_ewmh_get_desktop_names_reply(&xcb->ewmh, prop_cookie, &names,
NULL)) {
has_names = TRUE;
}
// calc widths of fields
for (i = clients.windows_len - 1; i > -1; i--) {
client *c = window_client(pd, clients.windows[i]);
if ((c != NULL) && !c->xattr.override_redirect &&
!client_has_window_type(c, xcb->ewmh._NET_WM_WINDOW_TYPE_DOCK) &&
!client_has_window_type(c, xcb->ewmh._NET_WM_WINDOW_TYPE_DESKTOP) &&
!client_has_state(c, xcb->ewmh._NET_WM_STATE_SKIP_PAGER) &&
!client_has_state(c, xcb->ewmh._NET_WM_STATE_SKIP_TASKBAR)) {
client *winclient = window_client(pd, clients.windows[i]);
if ((winclient != NULL) && !winclient->xattr.override_redirect &&
!client_has_window_type(winclient,
xcb->ewmh._NET_WM_WINDOW_TYPE_DOCK) &&
!client_has_window_type(winclient,
xcb->ewmh._NET_WM_WINDOW_TYPE_DESKTOP) &&
!client_has_state(winclient, xcb->ewmh._NET_WM_STATE_SKIP_PAGER) &&
!client_has_state(winclient, xcb->ewmh._NET_WM_STATE_SKIP_TASKBAR)) {
pd->clf_len =
MAX(pd->clf_len,
(c->class != NULL) ? (g_utf8_strlen(c->class, -1)) : 0);
MAX(pd->clf_len, (winclient->class != NULL)
? (g_utf8_strlen(winclient->class, -1))
: 0);
if (client_has_state(c, xcb->ewmh._NET_WM_STATE_DEMANDS_ATTENTION)) {
c->demands = TRUE;
if (client_has_state(winclient,
xcb->ewmh._NET_WM_STATE_DEMANDS_ATTENTION)) {
winclient->demands = TRUE;
}
if ((c->hint_flags & XCB_ICCCM_WM_HINT_X_URGENCY) != 0) {
c->demands = TRUE;
if ((winclient->hint_flags & XCB_ICCCM_WM_HINT_X_URGENCY) != 0) {
winclient->demands = TRUE;
}
if (c->window == curr_win_id) {
c->active = TRUE;
if (winclient->window == curr_win_id) {
winclient->active = TRUE;
}
// find client's desktop.
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *r;
c->wmdesktop = 0xFFFFFFFF;
cookie = xcb_get_property(xcb->connection, 0, c->window,
winclient->wmdesktop = 0xFFFFFFFF;
cookie = xcb_get_property(xcb->connection, 0, winclient->window,
xcb->ewmh._NET_WM_DESKTOP, XCB_ATOM_CARDINAL,
0, 1);
r = xcb_get_property_reply(xcb->connection, cookie, NULL);
if (r) {
if (r->type == XCB_ATOM_CARDINAL) {
c->wmdesktop = *((uint32_t *)xcb_get_property_value(r));
winclient->wmdesktop = *((uint32_t *)xcb_get_property_value(r));
}
free(r);
}
if (c->wmdesktop != 0xFFFFFFFF) {
if (winclient->wmdesktop != 0xFFFFFFFF) {
if (has_names) {
if ((current_window_manager & WM_PANGO_WORKSPACE_NAMES) ==
WM_PANGO_WORKSPACE_NAMES) {
char *output = NULL;
if (pango_parse_markup(_window_name_list_entry(names.strings,
names.strings_len,
c->wmdesktop),
-1, 0, NULL, &output, NULL, NULL)) {
c->wmdesktopstr = g_strdup(_window_name_list_entry(
names.strings, names.strings_len, c->wmdesktop));
c->wmdesktopstr_len = g_utf8_strlen(output, -1);
pd->wmdn_len = MAX(pd->wmdn_len, c->wmdesktopstr_len);
if (pango_parse_markup(
_window_name_list_entry(names.strings, names.strings_len,
winclient->wmdesktop),
-1, 0, NULL, &output, NULL, NULL)) {
winclient->wmdesktopstr = g_strdup(_window_name_list_entry(
names.strings, names.strings_len, winclient->wmdesktop));
winclient->wmdesktopstr_len = g_utf8_strlen(output, -1);
pd->wmdn_len = MAX(pd->wmdn_len, winclient->wmdesktopstr_len);
g_free(output);
} else {
c->wmdesktopstr = g_strdup("Invalid name");
pd->wmdn_len =
MAX(pd->wmdn_len, g_utf8_strlen(c->wmdesktopstr, -1));
winclient->wmdesktopstr = g_strdup("Invalid name");
pd->wmdn_len = MAX(pd->wmdn_len,
g_utf8_strlen(winclient->wmdesktopstr, -1));
}
} else {
c->wmdesktopstr = g_markup_escape_text(
winclient->wmdesktopstr = g_markup_escape_text(
_window_name_list_entry(names.strings, names.strings_len,
c->wmdesktop),
winclient->wmdesktop),
-1);
pd->wmdn_len =
MAX(pd->wmdn_len, g_utf8_strlen(c->wmdesktopstr, -1));
MAX(pd->wmdn_len, g_utf8_strlen(winclient->wmdesktopstr, -1));
}
} else {
c->wmdesktopstr = g_strdup_printf("%u", (uint32_t)c->wmdesktop);
winclient->wmdesktopstr =
g_strdup_printf("%u", (uint32_t)winclient->wmdesktop);
pd->wmdn_len =
MAX(pd->wmdn_len, g_utf8_strlen(c->wmdesktopstr, -1));
MAX(pd->wmdn_len, g_utf8_strlen(winclient->wmdesktopstr, -1));
}
} else {
c->wmdesktopstr = g_strdup("");
pd->wmdn_len = MAX(pd->wmdn_len, g_utf8_strlen(c->wmdesktopstr, -1));
winclient->wmdesktopstr = g_strdup("");
pd->wmdn_len =
MAX(pd->wmdn_len, g_utf8_strlen(winclient->wmdesktopstr, -1));
}
if (cd && c->wmdesktop != current_desktop) {
if (cd && winclient->wmdesktop != current_desktop) {
continue;
}
winlist_append(pd->ids, c->window, NULL);
winlist_append(pd->ids, winclient->window, NULL);
}
}

View File

@ -502,13 +502,13 @@ void rofi_theme_print_index(ThemeWidget *widget, int index) {
}
if (g_list_length(list) > 0) {
printf("%*s", index, "");
for (GList *iter = g_list_first(list); iter != NULL;
iter = g_list_next(iter)) {
char *name = (char *)iter->data;
for (GList *citer = g_list_first(list); citer != NULL;
citer = g_list_next(citer)) {
char *name = (char *)citer->data;
fputs(name, stdout);
if (iter->prev == NULL && iter->next) {
if (citer->prev == NULL && citer->next) {
putchar(' ');
} else if (iter->next) {
} else if (citer->next) {
putchar('.');
}
}
@ -519,13 +519,13 @@ void rofi_theme_print_index(ThemeWidget *widget, int index) {
size_t property_name_length = 0;
g_hash_table_iter_init(&iter, widget->properties);
while (g_hash_table_iter_next(&iter, &key, &value)) {
Property *p = (Property *)value;
property_name_length = MAX(strlen(p->name), property_name_length);
Property *pv = (Property *)value;
property_name_length = MAX(strlen(pv->name), property_name_length);
}
g_hash_table_iter_init(&iter, widget->properties);
while (g_hash_table_iter_next(&iter, &key, &value)) {
Property *p = (Property *)value;
rofi_theme_print_property_index(property_name_length, index + 4, p);
Property *pv = (Property *)value;
rofi_theme_print_property_index(property_name_length, index + 4, pv);
}
printf("%*s}\n", index, "");
g_list_free(list);
@ -753,9 +753,9 @@ static int rofi_theme_get_position_inside(Property *p, const widget *widget,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_POSITION, property, FALSE);
return rofi_theme_get_position_inside(p, widget, property, def);
return rofi_theme_get_position_inside(pv, widget, property, def);
}
return def;
}
@ -778,9 +778,9 @@ static int rofi_theme_get_integer_inside(Property *p, const widget *widget,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_INTEGER, property, FALSE);
return rofi_theme_get_integer_inside(p, widget, property, def);
return rofi_theme_get_integer_inside(pv, widget, property, def);
}
return def;
}
@ -805,9 +805,10 @@ static RofiDistance rofi_theme_get_distance_inside(Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_PADDING, property, FALSE);
return rofi_theme_get_distance_inside(p, widget->parent, property, def);
return rofi_theme_get_distance_inside(pv, widget->parent, property,
def);
}
return (RofiDistance){
.base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL},
@ -840,9 +841,9 @@ static int rofi_theme_get_boolean_inside(Property *p, const widget *widget,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_BOOLEAN, property, FALSE);
return rofi_theme_get_boolean_inside(p, widget, property, def);
return rofi_theme_get_boolean_inside(pv, widget, property, def);
}
return def;
}
@ -868,9 +869,9 @@ static RofiOrientation rofi_theme_get_orientation_inside(Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_ORIENTATION, property, FALSE);
return rofi_theme_get_orientation_inside(p, widget, property, def);
return rofi_theme_get_orientation_inside(pv, widget, property, def);
}
return def;
}
@ -897,9 +898,9 @@ static RofiCursorType rofi_theme_get_cursor_type_inside(Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_CURSOR, property, FALSE);
return rofi_theme_get_cursor_type_inside(p, widget, property, def);
return rofi_theme_get_cursor_type_inside(pv, widget, property, def);
}
return def;
}
@ -925,9 +926,9 @@ static const char *rofi_theme_get_string_inside(Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_STRING, property, FALSE);
return rofi_theme_get_string_inside(p, widget, property, def);
return rofi_theme_get_string_inside(pv, widget, property, def);
}
return def;
}
@ -951,9 +952,9 @@ static double rofi_theme_get_double_inside(ThemeWidget *wid, Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_DOUBLE, property, FALSE);
return rofi_theme_get_double_inside(parent, p, widget, property, def);
return rofi_theme_get_double_inside(parent, pv, widget, property, def);
}
return def;
}
@ -966,10 +967,10 @@ static double rofi_theme_get_double_inside(ThemeWidget *wid, Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_INTEGER, property, FALSE);
return rofi_theme_get_double_inside(parent, p, widget->parent, property,
def);
return rofi_theme_get_double_inside(parent, pv, widget->parent,
property, def);
}
return def;
}
@ -992,9 +993,9 @@ static void rofi_theme_get_color_inside(const widget *widget, Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_COLOR, property, FALSE);
rofi_theme_get_color_inside(widget, p, property, d);
rofi_theme_get_color_inside(widget, pv, property, d);
}
return;
}
@ -1020,9 +1021,9 @@ static gboolean rofi_theme_get_image_inside(Property *p, const widget *widget,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_IMAGE, property, FALSE);
return rofi_theme_get_image_inside(p, widget, property, d);
return rofi_theme_get_image_inside(pv, widget, property, d);
}
return FALSE;
}
@ -1132,9 +1133,9 @@ static RofiPadding rofi_theme_get_padding_inside(Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_PADDING, property, FALSE);
return rofi_theme_get_padding_inside(p, widget, property, pad);
return rofi_theme_get_padding_inside(pv, widget, property, pad);
}
return pad;
}
@ -1167,8 +1168,9 @@ static GList *rofi_theme_get_list_inside(Property *p, const widget *widget,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p = rofi_theme_find_property(parent, P_LIST, property, FALSE);
return rofi_theme_get_list_inside(p, widget, property, defaults);
Property *pv =
rofi_theme_find_property(parent, P_LIST, property, FALSE);
return rofi_theme_get_list_inside(pv, widget, property, defaults);
}
} else if (p->type == P_LIST) {
return g_list_copy_deep(p->value.list, rofi_g_list_strdup, NULL);
@ -1201,9 +1203,10 @@ rofi_theme_get_highlight_inside(Property *p, widget *widget,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pv =
rofi_theme_find_property(parent, P_HIGHLIGHT, property, FALSE);
return rofi_theme_get_highlight_inside(p, widget->parent, property, th);
return rofi_theme_get_highlight_inside(pv, widget->parent, property,
th);
}
return th;
}
@ -1502,9 +1505,9 @@ static gboolean rofi_theme_has_property_inside(Property *p,
if (widget->parent) {
ThemeWidget *parent =
rofi_theme_find_widget(widget->parent->name, widget->state, FALSE);
Property *p =
Property *pp =
rofi_theme_find_property(parent, P_STRING, property, FALSE);
return rofi_theme_has_property_inside(p, widget, property);
return rofi_theme_has_property_inside(pp, widget, property);
}
return FALSE;
}

View File

@ -2186,8 +2186,8 @@ void rofi_view_switch_mode(RofiViewState *state, Mode *mode) {
}
if (state->sidebar_bar) {
for (unsigned int j = 0; j < state->num_modi; j++) {
const Mode *mode = rofi_get_mode(j);
textbox_font(state->modi[j], (mode == state->sw) ? HIGHLIGHT : NORMAL);
const Mode *tb_mode = rofi_get_mode(j);
textbox_font(state->modi[j], (tb_mode == state->sw) ? HIGHLIGHT : NORMAL);
}
}
rofi_view_restart(state);

View File

@ -407,7 +407,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
return;
}
textbox *tb = (textbox *)wid;
unsigned int offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0);
unsigned int dot_offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0);
if (tb->changed) {
__textbox_update_pango_text(tb);
@ -429,7 +429,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
}
y += top;
x += offset;
x += dot_offset;
if (tb->xalign > 0.001) {
int rem =