summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-02-14 12:22:34 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2013-02-14 12:22:34 +0100
commit8e16853201f8a608905cacbf1c7e4fb8ac7e568e (patch)
tree073e2577816e39bc1bf9ac6a155e898d9a0748c1
parentde0092a1e986731a16faa510838afba9ae43fd78 (diff)
downloadcalcurse-8e16853201f8a608905cacbf1c7e4fb8ac7e568e.tar.gz
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>
-rw-r--r--src/utils.c10
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;
}