AmendHub

Download:

jcs

/

subtext

/

amendments

/

339

focusable: Allow add_focusable to fail


jcs made amendment 339 about 1 year ago
--- focusable.c Thu Jul 21 09:28:45 2022 +++ focusable.c Wed Mar 1 16:48:54 2023 @@ -35,14 +35,19 @@ find_focusable(GrafPtr win) return NULL; } -void +bool add_focusable(struct focusable *focusable) { short n; + struct focusable **new_focusables; + new_focusables = xreallocarray(focusables, sizeof(struct focusable *), + nfocusables + 1); + if (new_focusables == NULL) + return false; + + focusables = new_focusables; nfocusables++; - focusables = xreallocarray(focusables, sizeof(struct focusable *), - nfocusables); if (nfocusables > 1) for (n = nfocusables - 1; n > 0; n--) @@ -51,6 +56,7 @@ add_focusable(struct focusable *focusable) focusables[0] = focusable; show_focusable(focusable); + return true; } void --- focusable.h Fri Nov 18 14:30:12 2022 +++ focusable.h Wed Mar 1 16:49:32 2023 @@ -40,7 +40,7 @@ extern struct focusable **focusables; extern short nfocusables; struct focusable * find_focusable(GrafPtr win); -void add_focusable(struct focusable *focusable); +bool add_focusable(struct focusable *focusable); void show_focusable(struct focusable *focusable); void destroy_focusable(struct focusable *focusable); void hide_focusable(struct focusable *focusable);