main: Put all variable declarations at start of main to ensure decl

There is a chance that /end/ is jumped to without the FILE pointer or
stream actually being declared.  This deals with that.
This commit is contained in:
2026-02-05 18:39:31 +00:00
parent 3612313e76
commit f7cfe16c67

View File

@@ -24,6 +24,9 @@ void usage(FILE *fp)
int main(int argc, char *argv[])
{
int ret = 0;
FILE *pipe = NULL;
stream_t stream = {0};
if (argc == 1)
{
usage(stderr);
@@ -35,8 +38,6 @@ int main(int argc, char *argv[])
TODO("alisp doesn't support multiple files currently.");
}
FILE *fp = NULL;
stream_t stream = {0};
if (strncmp(argv[1], "--", 2) == 0)
{
stream_err_t err = stream_init_pipe(&stream, "stdin", stdin);
@@ -55,8 +56,8 @@ int main(int argc, char *argv[])
}
else
{
fp = fopen(argv[1], "rb");
stream_err_t err = stream_init_file(&stream, argv[1], fp);
pipe = fopen(argv[1], "rb");
stream_err_t err = stream_init_file(&stream, argv[1], pipe);
if (err)
{
fprintf(stderr, "ERROR: %s from `%s`\n", stream_err_to_cstr(err),
@@ -68,8 +69,8 @@ int main(int argc, char *argv[])
LOG("[INFO]: Initialised stream for `%s`\n", stream.name);
end:
if (fp)
fclose(fp);
if (pipe)
fclose(pipe);
stream_stop(&stream);
return ret;
}