commit 43dc5e539e8e84582ae74e854a91d640dca413f9
parent baa42cc90e2fa2a9f9ae14d0ae50216c2cd40155
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Mon, 21 Dec 2020 13:49:36 -0800
Fix error on a non-existent index
If an index which did not exist was given the `error` flag would
be unset causing it to attempt to print the status message.
To simplify, instead of setting the error flag when an error ocours
set it at the beginning only unsetting it on success.
Diffstat:
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/main.c b/main.c
@@ -457,7 +457,7 @@ cfetch(int argc, const char **argv, const char *cache, const char *host, const c
if (fp == NULL)
return 1;
- error = 0;
+ error = 1;
line = NULL;
size = 0;
for (i = 0; getline(&line, &size, fp) != -1; ++i) {
@@ -465,20 +465,18 @@ cfetch(int argc, const char **argv, const char *cache, const char *host, const c
continue;
if (argsplit(fields, LEN(fields), line, "\t\r\n") != LEN(fields) - 1) {
warnx("Not a valid gopher item.");
- ++error;
goto cleanup;
}
if (output == NULL)
if ((output = basename(fields[GI_PATH])) == NULL) {
warn("unable to get basename '%s'", fields[GI_PATH]);
- ++error;
goto cleanup;
}
- if (selwrite(fields[GI_HOST], fields[GI_PORT], fields[GI_PATH], output) != 0)
- ++error;
+ if (selwrite(fields[GI_HOST], fields[GI_PORT], fields[GI_PATH], output) == 0)
+ error = 0;
goto cleanup;
}
-
+ warnx("index too large");
cleanup:
#ifdef FETCH_MESSAGE
if (!error)