diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2013-02-14 12:22:34 +0100 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2013-02-14 12:22:34 +0100 |
commit | 8e16853201f8a608905cacbf1c7e4fb8ac7e568e (patch) | |
tree | 073e2577816e39bc1bf9ac6a155e898d9a0748c1 /src/utils.c | |
parent | de0092a1e986731a16faa510838afba9ae43fd78 (diff) | |
download | calcurse-8e16853201f8a608905cacbf1c7e4fb8ac7e568e.zip |
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 <calcurse@cryptocrack.de>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 10 |
1 files changed, 4 insertions, 6 deletions
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; } |