Skip to content

Commit

Permalink
Remove last uses of hsStrcpy and hsStrncpy
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Jan 27, 2025
1 parent 9b2f1e2 commit 2274800
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Sources/MaxPlugin/MaxComponent/plAudioComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ bool plBaseSoundEmitterComponent::LookupLatestAsset( const char *waveName, ch
}

// Copy the string over and go
hsStrcpy( retPath, assetPath );
strcpy(retPath, assetPath);
return true;
}

Expand Down
23 changes: 0 additions & 23 deletions Sources/Plasma/CoreLib/HeadSpin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,3 @@ void hsStatusMessageF(const char * fmt, ...)
}

#endif

/**************************************/
char* hsStrcpy(char* dst, const char* src)
{
if (src)
{
if (dst == nullptr)
{
size_t count = strlen(src);
dst = new char[count + 1];
memcpy(dst, src, count);
dst[count] = 0;
return dst;
}

int32_t i;
for (i = 0; src[i] != 0; i++)
dst[i] = src[i];
dst[i] = 0;
}

return dst;
}
14 changes: 0 additions & 14 deletions Sources/Plasma/CoreLib/HeadSpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,6 @@ template <> inline double hsToLE(double value) { return hsToLEDouble(value); }
void hsStatusMessageF(const char * fmt, ...);
#endif // PLASMA_EXTERNAL_RELEASE

char* hsStrcpy(char* dstOrNil, const char* src);

inline char* hsStrcpy(const char* src)
{
return hsStrcpy(nullptr, src);
}

inline char *hsStrncpy(char *strDest, const char *strSource, size_t count)
{
char *temp = strncpy(strDest, strSource, count-1);
strDest[count-1] = 0;
return temp;
}

// Use "correct" non-standard string functions based on the
// selected compiler / library
#if HS_BUILD_FOR_WIN32
Expand Down
9 changes: 8 additions & 1 deletion Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,14 @@ class plNetMsgGetSharedState : public plNetMsgObject
CLASSNAME_REGISTER( plNetMsgGetSharedState );
GETINTERFACE_ANY( plNetMsgGetSharedState, plNetMsgObject );

void SetSharedStateName(char* n) { if (n) hsStrncpy(fSharedStateName, n, kMaxNameLen); }
void SetSharedStateName(char* n)
{
if (n) {
strncpy(fSharedStateName, n, kMaxNameLen - 1);
fSharedStateName[kMaxNameLen - 1] = 0;
}
}

char* GetSharedStateName() { return fSharedStateName; }
};

Expand Down
7 changes: 5 additions & 2 deletions Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ bool plSimpleStateVariable::SetFromString(const ST::string& value, int idx, bool
int i=idx*fVar.GetAtomicCount();
for (std::vector<ST::string>::iterator ptr = bits.begin(); ptr != bits.end(); ++ptr)
{
hsStrncpy(fS32[i++], ptr->c_str(), 32);
plVarDescriptor::String32& dest = fS32[i];
strncpy(dest, ptr->c_str(), std::size(dest) - 1);
dest[std::size(dest) - 1] = 0;
i++;
}
}
break;
Expand Down Expand Up @@ -1730,7 +1733,7 @@ bool plSimpleStateVariable::Get(char value[], int idx) const

if (fVar.GetType()==plVarDescriptor::kString32)
{
hsStrcpy(value, fS32[idx]);
strcpy(value, fS32[idx]);
return true;
}
hsAssert(false, "passing wrong value type to SDL variable");
Expand Down

0 comments on commit 2274800

Please sign in to comment.