aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unit.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/unit.h b/unit.h
index fdb5a9a..a4c8b9d 100644
--- a/unit.h
+++ b/unit.h
@@ -169,7 +169,7 @@ get_unit_value(char const * string) {
for (; i < token_count;) {
if (tokens[i].type == ONE) {
- if (i == 0 && tokens[1].type == SLASH) {
+ if (i == 0 && token_count > 1 && tokens[1].type == SLASH) {
exp_sign = -1.0;
i += 2;
continue;
@@ -241,13 +241,13 @@ get_unit_value(char const * string) {
unit_found:
- if (tokens[i + 1].type != EXP) {
- value *= unit_value;
+ if (token_count <= i+1 || tokens[i + 1].type != EXP) {
+ value *= pow(unit_value, exp_sign);
i += 1;
continue;
}
- if (tokens[i + 2].type != NUMBER) goto error;
+ if (token_count <= i+2 || tokens[i + 2].type != NUMBER) goto error;
value *= pow(unit_value, exp_sign * tokens[i + 2].value.num);
i += 3;