Skip to content

Commit

Permalink
Make CTString::str_String field private to prevent its direct usage.
Browse files Browse the repository at this point in the history
CTString::Data() and CTString::ConstData() methods should be used instead to retrieve the string data instead of the field containing it.
  • Loading branch information
DreamyCecil committed Jan 29, 2025
1 parent f1968ec commit 04da505
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Sources/Engine/Base/CTString.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ struct VATypeVerifier
* Main string class
*/
class ENGINE_API CTString {
public:
// [Cecil] Use Data() or ConstData() from the outside instead of the field
private:
char *str_String; // pointer to memory holding the character string

public:
static const size_t npos; // [Cecil] Invalid character index

public:
Expand Down
6 changes: 3 additions & 3 deletions Sources/Engine/Query/LegacyClientQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif

extern unsigned char *gsseckey(u_char *secure, u_char *key, int enctype);
extern u_int resolv(char *host);
extern u_int resolv(const char *host); // [Cecil] 'char *' -> 'const char *'

// Buffer lengths
static const ULONG _ulBufferLength = 8192;
Expand Down Expand Up @@ -254,10 +254,10 @@ static void StartInternetSearch(void) {
#endif

// Connect to the master server
char *strMasterServer = _aProtocols[E_MS_LEGACY]->GetMS().str_String;
const CTString &strMasterServer = _aProtocols[E_MS_LEGACY]->GetMS();

sockaddr_in addr;
addr.sin_addr.s_addr = resolv(strMasterServer);
addr.sin_addr.s_addr = resolv(strMasterServer.ConstData());
addr.sin_port = htons(28900);
addr.sin_family = AF_INET;

Expand Down
2 changes: 1 addition & 1 deletion Sources/Engine/Query/LegacyFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ unsigned char *gsseckey(u_char *secure, u_char *key, int enctype) {
}

/* function resolv */
u_int resolv(char *host) {
u_int resolv(const char *host) {
struct hostent *hp;
u_int host_ip;

Expand Down
2 changes: 1 addition & 1 deletion Sources/Engine/Query/QueryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void SendPacketTo(sockaddr_in *psin, const char *pBuffer, int iLength, SOCKET iS

// Send reply packet with a message
void SendReply(const CTString &strMessage) {
SendPacketTo(&sinFrom, strMessage.str_String, strMessage.Length());
SendPacketTo(&sinFrom, strMessage.ConstData(), strMessage.Length());
};

// Receive some packet
Expand Down
2 changes: 1 addition & 1 deletion Sources/SeriousSam/SeriousSam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ int SubMain(HINSTANCE hInstance, const CommandLineSetup &cmd) {
strParam += " +connect " + _strModServerJoin + " +quickjoin";
}

if (!CreateProcessA(strCmd.str_String, strParam.str_String, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &cif, &pi)) {
if (!CreateProcessA(strCmd.ConstData(), strParam.Data(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &cif, &pi)) {
// [Cecil] Proper error message
ErrorMessage(TRANS("Cannot start '%s' mod:\n%s"), strMod.ConstData(), GetWindowsError(GetLastError()).ConstData());
}
Expand Down

0 comments on commit 04da505

Please sign in to comment.