commit 9bc2babf44d5ec02260c65fe4df4e60995dfc203
parent a60d13d524fc9eeb6edb6fd134150e69e8f12adb
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Fri, 15 Oct 2021 13:40:48 +0000
richterm: fix user menu array index misaligment
Diffstat:
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/richterm.c b/richterm.c
@@ -50,6 +50,7 @@ void rplumb(Object *);
char *ritems[] = {"Follow", "Snarf", "Plumb", nil};
void (*rfunc[])(Object *) = {rfollow, rsnarf, rplumb, nil};
+int rsize = sizeof(ritems) / sizeof(*ritems);
char * rgen(int);
Menu rmenu = {
@@ -348,7 +349,7 @@ mouse(Mousectl *mc, Mouse mv, int *mmode)
if ((obj != nil) && (obj->dlink->count > 0)) {
f = menuhit(3, mc, &rmenu, nil);
if (f >= 0) {
- if (f >= sizeof(ritems) - 1) ruseract(f - 2);
+ if (f >= rsize - 1) ruseract(f - rsize + 1);
else rfunc[f](obj);
}
} else if (menubuf->count > 0) {
@@ -814,8 +815,8 @@ objsettext(Object *obj, char *data, long count)
char *
rgen(int n)
{
- if (n < 3) return ritems[n];
- else return rusergen(n - 3);
+ if (n < rsize - 1) return ritems[n];
+ else return rusergen(n - rsize + 1);
}
void
@@ -870,6 +871,10 @@ ruseract(int f)
Array *a;
char *s;
s = rusergen(f);
+ if (s == nil) {
+ print("ruseract: nil string\n");
+ return;
+ }
a = arraycreate(sizeof(char), 2048, nil);
arraygrow(a, 5, "menu ");
arraygrow(a, strlen(s), s);