Amiga: fix extended-command menu mouse-pick
The amii_get_ext_cmd menu used the first character of each command as the item identity (id.a_char) and then linearly searched extcmdlist for the first command starting with that character. Many commands share a first letter, so picking #airlevel returned #adjust, #wipe returned #wear, etc. Store the actual index in id.a_int and read it back directly. While in that function, size obufp at BUFSZ (was 100) and replace the unbounded strcpy from extcmdlist[i].ef_txt with strncpy + explicit NUL.
This commit is contained in:
+6
-8
@@ -375,7 +375,7 @@ amii_get_ext_cmd(void)
|
|||||||
int bottom = 0;
|
int bottom = 0;
|
||||||
|
|
||||||
struct Window *w;
|
struct Window *w;
|
||||||
char obufp[100];
|
char obufp[BUFSZ];
|
||||||
char *bufp = obufp;
|
char *bufp = obufp;
|
||||||
int c;
|
int c;
|
||||||
int com_index, oindex;
|
int com_index, oindex;
|
||||||
@@ -417,7 +417,7 @@ amii_get_ext_cmd(void)
|
|||||||
amii_start_menu(win, MENU_BEHAVE_STANDARD);
|
amii_start_menu(win, MENU_BEHAVE_STANDARD);
|
||||||
|
|
||||||
for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) {
|
for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) {
|
||||||
id.a_char = extcmdlist[i].ef_txt[0];
|
id.a_int = i;
|
||||||
sprintf(buf, "%-10s - %s ", extcmdlist[i].ef_txt,
|
sprintf(buf, "%-10s - %s ", extcmdlist[i].ef_txt,
|
||||||
extcmdlist[i].ef_desc);
|
extcmdlist[i].ef_desc);
|
||||||
amii_add_menu(win, (const glyph_info *) 0, &id,
|
amii_add_menu(win, (const glyph_info *) 0, &id,
|
||||||
@@ -432,16 +432,14 @@ amii_get_ext_cmd(void)
|
|||||||
if (sel == 0) {
|
if (sel == 0) {
|
||||||
return (-1);
|
return (-1);
|
||||||
} else {
|
} else {
|
||||||
sel = mip->item.a_char;
|
i = mip->item.a_int;
|
||||||
for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) {
|
|
||||||
if (sel == extcmdlist[i].ef_txt[0])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy in the text */
|
/* copy in the text */
|
||||||
if (extcmdlist[i].ef_txt != NULL) {
|
if (extcmdlist[i].ef_txt != NULL) {
|
||||||
amii_clear_nhwindow(WIN_MESSAGE);
|
amii_clear_nhwindow(WIN_MESSAGE);
|
||||||
strcpy(bufp = obufp, extcmdlist[i].ef_txt);
|
strncpy(obufp, extcmdlist[i].ef_txt, sizeof(obufp) - 1);
|
||||||
|
obufp[sizeof(obufp) - 1] = '\0';
|
||||||
|
bufp = obufp;
|
||||||
(void) put_ext_cmd(obufp, colx, cw, bottom);
|
(void) put_ext_cmd(obufp, colx, cw, bottom);
|
||||||
return (i);
|
return (i);
|
||||||
} else
|
} else
|
||||||
|
|||||||
Reference in New Issue
Block a user