From 581e39ac203056633a627ad09167adf05753e091 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 7 Nov 2012 20:34:26 +0100 Subject: check bounds when accessing the transitions table --- parser.cpp | 16 +++++++++++++++- parser.h | 13 +------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/parser.cpp b/parser.cpp index 3178421..1ce6e2c 100644 --- a/parser.cpp +++ b/parser.cpp @@ -33,7 +33,7 @@ macro_execute(const gchar *macro) State::State() { - for (int i = 0; i < MAX_TRANSITIONS; i++) + for (guint i = 0; i < G_N_ELEMENTS(transitions); i++) transitions[i] = NULL; } @@ -64,6 +64,20 @@ State::input(gchar chr) return TRUE; } +State * +State::get_next_state(gchar chr) +{ + State *next = NULL; + guint upper = g_ascii_toupper(chr); + + if (upper < G_N_ELEMENTS(transitions)) + next = transitions[upper]; + if (!next) + next = custom(chr); + + return next; +} + StateStart::StateStart() : State() { transitions['\0'] = this; diff --git a/parser.h b/parser.h index 9cef0f6..dba304d 100644 --- a/parser.h +++ b/parser.h @@ -14,19 +14,8 @@ protected: public: State(); - inline State *& - operator [](int i) - { - return transitions[i]; - } - static gboolean input(gchar chr); - - inline State * - get_next_state(gchar chr) - { - return transitions[(int)g_ascii_toupper(chr)] ? : custom(chr); - } + State *get_next_state(gchar chr); virtual State * custom(gchar chr) -- cgit v1.2.3