--- dsimple.c.orig 2011-05-30 16:40:58.000000000 +0300 +++ dsimple.c 2011-05-30 16:52:19.000000000 +0300 @@ -247,6 +247,16 @@ xcb_get_property (Dpy, False, Win, atom_net_wm_name, \ atom_utf8_string, 0, BUFSIZ) +/* + * isequal: compare a null-terminated char* to a (not necessarily null- + * terminated) character array with a given legth, returning 1 if equal. + */ +static int +isequal ( + const char *a, const char *b, int a_len) +{ + return (strlen(b) == a_len) && (!strncmp(a, b, a_len)); +} static xcb_window_t recursive_Window_With_Name ( @@ -272,8 +282,7 @@ const char *prop_name = xcb_get_property_value (prop); int prop_name_len = xcb_get_property_value_length (prop); - /* can't use strcmp, since prop.name is not null terminated */ - if (strncmp (prop_name, name, prop_name_len) == 0) { + if (isequal (prop_name, name, prop_name_len)) { w = window; } } @@ -293,8 +302,7 @@ if (xcb_get_wm_name_reply (dpy, cookies->get_wm_name, &nameprop, &err)) { - /* can't use strcmp, since nameprop.name is not null terminated */ - if (strncmp (nameprop.name, name, nameprop.name_len) == 0) { + if (isequal (nameprop.name, name, nameprop.name_len)) { w = window; } @@ -308,8 +316,7 @@ const char *prop_name = xcb_get_property_value (prop); int prop_name_len = xcb_get_property_value_length (prop); - /* can't use strcmp, since prop.name is not null terminated */ - if (strncmp (prop_name, name, prop_name_len) == 0) { + if (isequal (prop_name, name, prop_name_len)) { w = window; } }