From 8e16853201f8a608905cacbf1c7e4fb8ac7e568e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 14 Feb 2013 12:22:34 +0100 Subject: parse_duration(): Bail out early in final state Bail out early if we are reading a character while being in a final state. Signed-off-by: Lukas Fleischer --- src/utils.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/utils.c b/src/utils.c index 7baa961..c20e767 100644 --- a/src/utils.c +++ b/src/utils.c @@ -785,11 +785,10 @@ int parse_duration(const char *string, unsigned *duration) /* parse string using a simple state machine */ for (p = string; *p; p++) { - if ((*p >= '0') && (*p <= '9')) { - if (state == STATE_DONE) - return 0; - else - in = in * 10 + (int)(*p - '0'); + if (state == STATE_DONE) { + return 0; + } else if ((*p >= '0') && (*p <= '9')) { + in = in * 10 + (int)(*p - '0'); } else { switch (state) { case STATE_INITIAL: @@ -826,7 +825,6 @@ int parse_duration(const char *string, unsigned *duration) return 0; break; case STATE_HHMM_MM: - case STATE_DONE: return 0; break; } -- cgit v1.2.3-70-g09d2