From 8a1c8115cad58586527b8461118917dc25653cd4 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 5 Aug 2012 16:34:38 +0200 Subject: [PATCH] fix a few warnings/places where the clang static analyzer complains --- i3-input/main.c | 10 ---------- i3-nagbar/main.c | 10 ++++++---- src/commands.c | 8 ++++++-- src/con.c | 3 +++ src/floating.c | 2 +- src/ipc.c | 2 +- src/key_press.c | 2 +- src/load_layout.c | 2 +- src/main.c | 3 +-- 9 files changed, 20 insertions(+), 22 deletions(-) diff --git a/i3-input/main.c b/i3-input/main.c index b5709523..7e236ca7 100644 --- a/i3-input/main.c +++ b/i3-input/main.c @@ -126,16 +126,6 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t static int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_event_t *event) { printf("releasing %d, state raw = %d\n", event->detail, event->state); - /* See the documentation of xcb_key_symbols_get_keysym for this one. - * Basically: We get either col 0 or col 1, depending on whether shift is - * pressed. */ - int col = (event->state & XCB_MOD_MASK_SHIFT); - - /* If modeswitch is currently active, we need to look in group 2 or 3, - * respectively. */ - if (modeswitch_active) - col += 2; - xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, event->state); if (sym == XK_Mode_switch) { printf("Mode switch disabled\n"); diff --git a/i3-nagbar/main.c b/i3-nagbar/main.c index 1dbd7736..87214477 100644 --- a/i3-nagbar/main.c +++ b/i3-nagbar/main.c @@ -216,7 +216,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) { } int main(int argc, char *argv[]) { - char *pattern = strdup("-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"); + char *pattern = sstrdup("-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"); int o, option_index = 0; enum { TYPE_ERROR = 0, TYPE_WARNING = 1 } bar_type = TYPE_ERROR; @@ -232,7 +232,7 @@ int main(int argc, char *argv[]) { char *options_string = "b:f:m:t:vh"; - prompt = strdup("Please do not run this program."); + prompt = sstrdup("Please do not run this program."); while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { switch (o) { @@ -241,11 +241,11 @@ int main(int argc, char *argv[]) { return 0; case 'f': FREE(pattern); - pattern = strdup(optarg); + pattern = sstrdup(optarg); break; case 'm': FREE(prompt); - prompt = strdup(optarg); + prompt = sstrdup(optarg); break; case 't': bar_type = (strcasecmp(optarg, "warning") == 0 ? TYPE_WARNING : TYPE_ERROR); @@ -432,5 +432,7 @@ int main(int argc, char *argv[]) { free(event); } + FREE(pattern); + return 0; } diff --git a/src/commands.c b/src/commands.c index 44e6a23d..964dfe29 100644 --- a/src/commands.c +++ b/src/commands.c @@ -452,7 +452,7 @@ void cmd_move_con_to_workspace_number(I3_CMD, char *which) { return; } - LOG("should move window to workspace with number %d\n", which); + LOG("should move window to workspace %s\n", which); /* get the workspace */ Con *output, *workspace = NULL; @@ -835,7 +835,7 @@ void cmd_workspace_number(I3_CMD, char *which) { child->num == parsed_num); if (!workspace) { - LOG("There is no workspace with number %d, creating a new one.\n", parsed_num); + LOG("There is no workspace with number %ld, creating a new one.\n", parsed_num); ysuccess(true); /* terminate the which string after the endposition of the number */ *endptr = '\0'; @@ -1421,6 +1421,10 @@ void cmd_layout(I3_CMD, char *layout_str) { layout = L_SPLITV; else if (strcmp(layout_str, "splith") == 0) layout = L_SPLITH; + else { + ELOG("Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str); + return; + } DLOG("changing layout to %s (%d)\n", layout_str, layout); diff --git a/src/con.c b/src/con.c index cb4d0805..01305f1a 100644 --- a/src/con.c +++ b/src/con.c @@ -1260,6 +1260,9 @@ bool con_fullscreen_permits_focusing(Con *con) { while (fs && fs->fullscreen_mode == CF_NONE) fs = fs->parent; + /* fs must be non-NULL since the workspace con doesn’t have CF_NONE and + * there always has to be a workspace con in the hierarchy. */ + assert(fs != NULL); /* The most common case is we hit the workspace level. In this * situation, changing focus is also harmless. */ assert(fs->fullscreen_mode != CF_NONE); diff --git a/src/floating.c b/src/floating.c index 0bc5f6d6..16aab992 100644 --- a/src/floating.c +++ b/src/floating.c @@ -493,7 +493,7 @@ void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t confine_to, border_t border, callback_t callback, const void *extra) { uint32_t new_x, new_y; - Rect old_rect; + Rect old_rect = { 0, 0, 0, 0 }; if (con != NULL) memcpy(&old_rect, &(con->rect), sizeof(Rect)); diff --git a/src/ipc.c b/src/ipc.c index 77b8dbb3..642b6b97 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -758,7 +758,7 @@ static int add_subscription(void *extra, const unsigned char *s, #endif ipc_client *client = extra; - DLOG("should add subscription to extra %p, sub %.*s\n", client, len, s); + DLOG("should add subscription to extra %p, sub %.*s\n", client, (int)len, s); int event = client->num_events; client->num_events++; diff --git a/src/key_press.c b/src/key_press.c index 9aaea8f9..68f3865a 100644 --- a/src/key_press.c +++ b/src/key_press.c @@ -291,7 +291,7 @@ void handle_key_press(xcb_key_press_event_t *event) { command_failed = false; yajl_status state = yajl_parse(handle, reply, length); if (state != yajl_status_ok) { - ELOG("Could not parse my own reply. That's weird. reply is %.*s\n", length, reply); + ELOG("Could not parse my own reply. That's weird. reply is %.*s\n", (int)length, reply); } else { if (command_failed) start_commanderror_nagbar(); diff --git a/src/load_layout.c b/src/load_layout.c index 54735d91..8596dfc4 100644 --- a/src/load_layout.c +++ b/src/load_layout.c @@ -139,7 +139,7 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) { #else static int json_string(void *ctx, const unsigned char *val, unsigned int len) { #endif - LOG("string: %.*s for key %s\n", len, val, last_key); + LOG("string: %.*s for key %s\n", (int)len, val, last_key); if (parsing_swallows) { /* TODO: the other swallowing keys */ if (strcasecmp(last_key, "class") == 0) { diff --git a/src/main.c b/src/main.c index b8e2e08c..aaa58171 100644 --- a/src/main.c +++ b/src/main.c @@ -424,7 +424,7 @@ int main(int argc, char *argv[]) { } optind++; } - LOG("Command is: %s (%d bytes)\n", payload, strlen(payload)); + DLOG("Command is: %s (%zd bytes)\n", payload, strlen(payload)); char *socket_path = root_atom_contents("I3_SOCKET_PATH"); if (!socket_path) { ELOG("Could not get i3 IPC socket path\n"); @@ -660,7 +660,6 @@ int main(int argc, char *argv[]) { Output *output = NULL; if (!(pointerreply = xcb_query_pointer_reply(conn, pointercookie, NULL))) { ELOG("Could not query pointer position, using first screen\n"); - output = get_first_output(); } else { DLOG("Pointer at %d, %d\n", pointerreply->root_x, pointerreply->root_y); output = get_output_containing(pointerreply->root_x, pointerreply->root_y); -- 2.39.5