From 0f6c54cf528151145f26058ff9551248fb643597 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Sun, 18 Aug 2024 05:49:24 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20Base=5Fdirectory=20before?= =?UTF-8?q?=20it=E2=80=99s=20been=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Descent3/sdlmain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Descent3/sdlmain.cpp b/Descent3/sdlmain.cpp index c7ab913af..1dc2cc0a1 100644 --- a/Descent3/sdlmain.cpp +++ b/Descent3/sdlmain.cpp @@ -252,7 +252,7 @@ oeD3LnxDatabase::oeD3LnxDatabase() : oeLnxAppDatabase() { char *netdir = getenv("D3_DIR"); if (!dir) - strcpy(path, Base_directory); + strcpy(path, ""); else strcpy(path, dir);