aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-20 18:03:08 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-20 18:03:08 +0000
commit229792aad759eb1bf8a67318e25baecc249273a8 (patch)
treeab0c856a5b96fe033defa233531fd3311f571c14
parent08b7eaa5b72aa523c982358c6edc948fca40420b (diff)
downloadtermo-229792aad759eb1bf8a67318e25baecc249273a8.tar.gz
termo-229792aad759eb1bf8a67318e25baecc249273a8.tar.xz
termo-229792aad759eb1bf8a67318e25baecc249273a8.zip
Handle realloc() failures when registering key names
-rw-r--r--termkey.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/termkey.c b/termkey.c
index 7b5bc01..77a028f 100644
--- a/termkey.c
+++ b/termkey.c
@@ -239,7 +239,8 @@ static TermKey *termkey_new_full(int fd, int flags, size_t buffsize, int waittim
tk->method.peekkey_mouse = &peekkey_mouse;
for(i = 0; keynames[i].name; i++)
- termkey_register_keyname(tk, keynames[i].sym, keynames[i].name);
+ if(termkey_register_keyname(tk, keynames[i].sym, keynames[i].name) == -1)
+ goto abort_free_keynames;
register_c0(tk, TERMKEY_SYM_BACKSPACE, 0x08, NULL);
register_c0(tk, TERMKEY_SYM_TAB, 0x09, NULL);
@@ -1017,7 +1018,9 @@ TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *nam
if(sym >= tk->nkeynames) {
const char **new_keynames = realloc(tk->keynames, sizeof(new_keynames[0]) * (sym + 1));
- // TODO: Handle realloc() failure
+ if(!new_keynames)
+ return -1;
+
tk->keynames = new_keynames;
// Fill in the hole