commit d611611a87d9bc3ab71c10d94634e56435aade64
parent 2fe4da70f4d183072eed2ba1310cdec66c107dcd
Author: phoebos <ben@bvnf.space>
Date: Wed, 25 May 2022 13:14:37 +0100
don't accept unsupported i/o bases
Diffstat:
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/README b/README
@@ -76,8 +76,7 @@ BUGS
Since baddc uses integers internally, all the operations perform integer
(floor) rounding which may be lossy.
- baddc allows any number to be used as the input base, but only
- hexadecimal numbers (0-9A-Z) may be input.
+ The only supported values of input base are 1-16.
The only supported values of output base are 8, 10, 16.
diff --git a/baddc.1 b/baddc.1
@@ -97,10 +97,7 @@ uses integers internally, all the operations perform integer
.Pq floor
rounding which may be lossy.
.Pp
-.Nm
-allows any number to be used as the input base, but only hexadecimal numbers
-.Pq 0-9A-Z
-may be input.
+The only supported values of input base are 1-16.
.Pp
The only supported values of output base are 8, 10, 16.
.Sh AUTHORS
diff --git a/baddc.c b/baddc.c
@@ -96,7 +96,11 @@ void divide(void) {
}
void i_base(void) {
- ibase = pop();
+ int i = pop();
+ if (i > 16 || i < 1)
+ fprintf(stderr, "input base %d not supported!\n", i);
+ else
+ ibase = i;
}
void I_base(void) {
@@ -104,7 +108,11 @@ void I_base(void) {
}
void o_base(void) {
- obase = pop();
+ int o = pop();
+ if (o != 8 || o != 10 || o != 16)
+ fprintf(stderr, "output base %d not supported!\n", o);
+ else
+ obase = o;
}
void O_base(void) {
@@ -183,7 +191,7 @@ int main(int argc, char **argv) {
if (buf[i] == '_')
neg = -1;
else if (buf[i] == '.')
- fprintf(stderr, "no floating point please\n");
+ fprintf(stderr, "no floating point please!\n");
else if (isdigit(buf[i])) {
curnum = (curnum * ibase) + (buf[i] - '0');
numready = 1;