aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-11-12 16:10:58 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-11-12 16:10:58 +0000
commit04e1926df66e20bcae2cc7d0233449b982a04d20 (patch)
tree5745dd4b1909fa48b936291b7391363496b6749f
parent62c5c970808072b76078523432e43db1d2488b93 (diff)
downloadtermo-04e1926df66e20bcae2cc7d0233449b982a04d20.tar.gz
termo-04e1926df66e20bcae2cc7d0233449b982a04d20.tar.xz
termo-04e1926df66e20bcae2cc7d0233449b982a04d20.zip
Handle malloc() failures during setup of driver-ti
-rw-r--r--driver-ti.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/driver-ti.c b/driver-ti.c
index 7c5a6f0..f65f474 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -24,7 +24,7 @@ typedef struct {
} termkey_ti;
static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmask, int *modsetp);
-static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset);
+static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset);
static void *new_driver(termkey_t *tk, const char *term)
{
@@ -66,11 +66,15 @@ static void *new_driver(termkey_t *tk, const char *term)
continue;
if(sym != TERMKEY_SYM_NONE)
- register_seq(ti, value, type, sym, mask, set);
+ if(!register_seq(ti, value, type, sym, mask, set))
+ goto abort_free_seqs;
}
return ti;
+abort_free_seqs:
+ free(ti->seqs);
+
abort_free_ti:
free(ti);
@@ -240,12 +244,13 @@ static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_ke
return 0;
}
-static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset)
+static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset)
{
if(ti->nseqs == ti->alloced_seqs) {
ti->alloced_seqs *= 2;
void *newseqs = realloc(ti->seqs, ti->alloced_seqs * sizeof(ti->seqs[9]));
- // TODO: Handle realloc() failure
+ if(!newseqs)
+ return 0;
ti->seqs = newseqs;
}
@@ -256,6 +261,8 @@ static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, ter
ti->seqs[i].key.sym = sym;
ti->seqs[i].key.modifier_mask = modmask;
ti->seqs[i].key.modifier_set = modset;
+
+ return 1;
}
struct termkey_driver termkey_driver_ti = {