aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-01-10 15:18:01 -0500
committerB. Watson <urchlay@slackware.uk>2024-01-10 15:18:01 -0500
commitf7d93dca4ba67c8c522428fc4cf5ed551fa9920b (patch)
treecc95bef935e56d746bbf85fce1ca1227612c78b3
parent00331a6f21437941f40f351f0bf059e38f009336 (diff)
downloadhcalc-master.tar.gz
Paranoia for config file: make sure we never load/save bad FP values.HEADmaster
-rw-r--r--config.c10
-rw-r--r--hcalc.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/config.c b/config.c
index 2e644b5..dbf7a64 100644
--- a/config.c
+++ b/config.c
@@ -40,6 +40,12 @@ struct hcalc_config {
char *home_dir = NULL;
char config_path[MAX_HOME]; /* ludicrous size */
+void validate_numbers(void) {
+ if(!number_is_ok(value)) value = 0;
+ if(!number_is_ok(saved)) saved = 0;
+ if(!number_is_ok(stored)) stored = 0;
+}
+
size_t filesize(FILE *f) {
struct stat st;
@@ -121,6 +127,8 @@ void load_config(void) {
winsize = conf.winsize;
base = conf.base;
quiet = conf.quiet;
+
+ validate_numbers();
}
void save_config(void) {
@@ -142,6 +150,8 @@ void save_config(void) {
return;
}
+ validate_numbers();
+
memcpy(conf.signature, SIGNATURE, SIGLEN);
conf.doublesize = sizeof(double);
conf.value = value;
diff --git a/hcalc.h b/hcalc.h
index 44d4cc0..06a8428 100644
--- a/hcalc.h
+++ b/hcalc.h
@@ -63,5 +63,6 @@ void show_value(void);
void bell(void);
void copy(void);
void paste(void);
+int number_is_ok(double n);
#define MAXCHARS 15