Skip to content

Commit

Permalink
Don’t use Base_directory before it’s been set
Browse files Browse the repository at this point in the history
Before this change, the Base_directory variable would get accessed
before we set its value. This seems to be OK. I’m not sure about the
details, but it seems like C++ guarantees that Base_directory will be
filled with zeros when it’s created.

That being said, the code that was modified by this commit used to be
misleading. The code would copy the contents of the Base_directory
variable into another variable named path. If you read the code, you
would think that path would be set to something along the lines of
"C:\\Games\\Descent3" or "/home/username/D3-open-source", but in
reality, path would be set to "". This change makes it clear that path
is guaranteed to be set to "".

The main motivation behind this commit is to make it easier to create a
future commit. That future commit will replace Base_directory with a new
variable named Base_directories. Base_directories will have a different
data type that does not get filled with zeros by default. In other
words, we need to set the new Base_directories variable before we use
it. Unfortunately, neither the current Base_directory variable nor the
future Base_directories variable will get set in time. Both of them will
be set after path variable gets set. This commit allows me to not worry
about that detail when I create the future Base_directories commit.
  • Loading branch information
Jayman2000 committed Sep 20, 2024
1 parent 84c1e2c commit 16cf59b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Descent3/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class oeD3LnxDatabase : public oeLnxAppDatabase {
char *netdir = getenv("D3_DIR");

if (!dir)
strcpy(path, Base_directory);
strcpy(path, "");
else
strcpy(path, dir);

Expand Down

0 comments on commit 16cf59b

Please sign in to comment.