Fix a segmentation fault occuring when using menu_add_item without a text

label. While there sync code and documentation about the possibility to use
a label and options.
This commit is contained in:
mmdolze
2012-10-10 16:29:39 +00:00
parent d3cc108f57
commit f36642ab69
3 changed files with 21 additions and 8 deletions
+1
View File
@@ -31,6 +31,7 @@ v0.5dev (ongoing development)
* hd44780/serial: Add support for adjustable backlight
* Build system: Fix build with automake >= 1.11.3 (#3494755)
* Fix clang compiler warnings about obsolete GNU designated initializers
* Fix crash when adding a menu item without text and options (S. Dawson)
v0.5.5
+ sed1330 driver: Add support for HG25504 (L. Lagendijk)
+12 -3
View File
@@ -707,6 +707,7 @@
menu_set_item "test" test_ip -next "test_menu" -prev "test_alpha"
menu_set_item "test" test_menu_action -next "_close_"
# replace the main menu with the client's menu as created above
menu_set_main ""
</programlisting>
</para>
@@ -757,7 +758,8 @@
<option><replaceable>menu_id</replaceable></option>
<option><replaceable>new_item_id</replaceable></option>
<option><replaceable>type</replaceable></option>
<optional><option><replaceable>options</replaceable></option></optional>
<optional><option><replaceable>text</replaceable></option></optional>
<optional><option><replaceable>item_specific_options</replaceable></option></optional>
</command>
</term>
<listitem>
@@ -765,8 +767,10 @@
Adds a new menu item to a menu. The main menu of a client,
will be created automatically as soon as the client adds
an item. This main menu has an empty id ("") and the name
is identical to the name of the client. The options are
described under menu_set_item below.
is identical to the name of the client. The item specific options
are described under menu_set_item below. Use of <replaceable>text</replaceable>
is optional and is a shortcut for "-text <replaceable>text</replaceable>"
option.
</para>
<para>
<note>
@@ -777,6 +781,11 @@
<replaceable>menu_ids</replaceable> are <emphasis>unique</emphasis>
(at least within a clients menu hierarchy).
</para>
<para>
If you want to use a text label that starts with a '-' (minus)
character, you have to use the "-text <replaceable>text</replaceable>"
option.
</para>
</note>
<variablelist><title>menu item types</title>
<varlistentry>
+8 -5
View File
@@ -67,13 +67,14 @@ static char *argv2string(int argc, char **argv)
* Adds an item to a menu.
*
*\verbatim
* Usage: menu_add_item <menuid> <newitemid> <type> [<text>]
* Usage: menu_add_item <menuid> <newitemid> <type> [<text>] {<option>}+
*\endverbatim
*
* You should use "" as id for the client's main menu. This menu will be
* created automatically when you add an item to it the first time.
*
* You (currently?) cannot create a menu in the main level yourself.
* You cannot create a menu in the main level yourself, unless you replace the
* main menu with the client's menu.
* The names you use for items should be unique for your client.
* The text is the visible text for the item.
*
@@ -86,6 +87,8 @@ static char *argv2string(int argc, char **argv)
* - numeric
* - alpha
* - ip
*
* For the list of supported options see menu_set_item_func.
*/
int
menu_add_item_func(Client *c, int argc, char **argv)
@@ -108,7 +111,7 @@ menu_add_item_func(Client *c, int argc, char **argv)
}
if (argc < 4) {
sock_send_error(c->sock, "Usage: menu_add_item <menuid> <newitemid> <type> [<text>]\n");
sock_send_error(c->sock, "Usage: menu_add_item <menuid> <newitemid> <type> [<text>] [<option>]+\n");
return 0;
}
@@ -198,8 +201,8 @@ menu_add_item_func(Client *c, int argc, char **argv)
/* call menu_set_item() with a temporarily allocated argv
* to process the remaining options */
if ((argc > 5) || (argv[4][0] == '-')) {
// menu_add_item <menuid> <newitemid> <type> [<text>]
if ((argc > 5) || ((argc == 5) && (argv[4][0] == '-'))) {
// menu_add_item <menuid> <newitemid> <type> [<text>] [<option>]+
// menu_set_item <menuid> <itemid> {<option>}+
int i, j;
char **tmp_argv = malloc(argc * sizeof(char *));