diff --git a/build-utils/layoutgen.sh b/build-utils/layoutgen.sh index 804ea7252..db8e41afd 100755 --- a/build-utils/layoutgen.sh +++ b/build-utils/layoutgen.sh @@ -16,9 +16,9 @@ do grep '^layout_t layout_' $file | cut -d' ' -f2 | cut -d\; -f1 | while read layout do shortname=`echo $layout | cut -d _ -f2-` - echo " {\"$shortname\", $layout}," + echo " {\"$shortname\", sizeof(\"$shortname\") - 1, $layout}," done done -echo " {NULL, NULL}" +echo " {NULL, 0, NULL}" echo "};" diff --git a/build-utils/widgetgen.sh b/build-utils/widgetgen.sh index 037d3dbda..ae71b0bd3 100755 --- a/build-utils/widgetgen.sh +++ b/build-utils/widgetgen.sh @@ -10,9 +10,9 @@ do grep '^widget_constructor_t ' "$file" | cut -d' ' -f2 | cut -d\; -f1 | while read widget do shortname=`echo $widget | cut -d_ -f2` - echo " {\"$shortname\", $widget}," + echo " {\"$shortname\", sizeof(\"$shortname\") - 1, $widget}," done done -echo " {NULL, NULL}" +echo " {NULL, 0, NULL}" echo "};" diff --git a/common/util.c b/common/util.c index 1833e8b29..b72f61836 100644 --- a/common/util.c +++ b/common/util.c @@ -59,17 +59,18 @@ _warn(int line, const char *fct, const char *fmt, ...) /** Lookup for a function pointer from its name * in the given name_func_link_t list. * \param funcname Function name. + * \param len The function name length. * \param list Function and name link list. * \return Function pointer. */ void * -name_func_lookup(const char *funcname, const name_func_link_t *list) +name_func_lookup(const char *funcname, size_t len, const name_func_link_t *list) { int i; if(funcname && list) for(i = 0; list[i].name; i++) - if(!a_strcmp(funcname, list[i].name)) + if(len == list[i].len && !a_strcmp(funcname, list[i].name)) return list[i].func; return NULL; diff --git a/common/util.h b/common/util.h index 7dc3be8ab..b06169091 100644 --- a/common/util.h +++ b/common/util.h @@ -60,6 +60,7 @@ typedef enum typedef struct { const char *name; + size_t len; void *func; } name_func_link_t; @@ -351,7 +352,7 @@ position_t position_fromstr(const char *, ssize_t); const char * position_tostr(position_t); orientation_t orientation_fromstr(const char *, ssize_t); const char * orientation_tostr(orientation_t); -void *name_func_lookup(const char *, const name_func_link_t *); +void *name_func_lookup(const char *, size_t, const name_func_link_t *); const char * name_func_rlookup(void *, const name_func_link_t *); void a_exec(const char *); char ** a_strsplit(const char *, ssize_t, char); diff --git a/tag.c b/tag.c index 1d03e8adf..7af7b6fca 100644 --- a/tag.c +++ b/tag.c @@ -271,7 +271,7 @@ tag_view_only_byindex(int screen, int dindex) static int luaA_tag_new(lua_State *L) { - size_t len; + size_t len, laylen; tag_t *tag; int ncol, nmaster; const char *name, *lay; @@ -286,9 +286,9 @@ luaA_tag_new(lua_State *L) mwfact = luaA_getopt_number(L, 2, "mwfact", 0.5); ncol = luaA_getopt_number(L, 2, "ncol", 1); nmaster = luaA_getopt_number(L, 2, "nmaster", 1); - lay = luaA_getopt_string(L, 2, "layout", "tile"); + lay = luaA_getopt_lstring(L, 2, "layout", "tile", &laylen); - layout = name_func_lookup(lay, LayoutList); + layout = name_func_lookup(lay, laylen, LayoutList); tag = tag_new(name, len, layout, @@ -430,8 +430,8 @@ luaA_tag_newindex(lua_State *L) tag_append_to_screen(*tag, &globalconf.screens[screen]); break; case A_TK_LAYOUT: - buf = luaL_checkstring(L, 3); - l = name_func_lookup(buf, LayoutList); + buf = luaL_checklstring(L, 3, &len); + l = name_func_lookup(buf, len, LayoutList); if(l) (*tag)->layout = l; else diff --git a/widget.c b/widget.c index c8ce4660c..4fa677fc1 100644 --- a/widget.c +++ b/widget.c @@ -329,10 +329,9 @@ luaA_widget_new(lua_State *L) luaA_checktable(L, 2); - align = luaA_getopt_lstring(L, 2, "align", "left", &len); - type = luaA_getopt_string(L, 2, "type", NULL); + type = luaA_getopt_lstring(L, 2, "type", NULL, &len); - if((wc = name_func_lookup(type, WidgetList))) + if((wc = name_func_lookup(type, len, WidgetList))) { w = p_new(widget_t, 1); wc(w); @@ -344,6 +343,8 @@ luaA_widget_new(lua_State *L) } w->type = wc; + + align = luaA_getopt_lstring(L, 2, "align", "left", &len); w->align_supported |= AlignLeft | AlignRight; w->align = draw_align_fromstr(align, len);