mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
Merge #3195
3195: Use str_truncate more often r=heinrich5991 a=def- <!-- What is the motivation for the changes of this pull request --> ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Dennis Felsing <dennis@felsin9.de>
This commit is contained in:
commit
9a257a76e1
|
@ -326,7 +326,7 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
for(m_PlaceholderLength = 0; *pCursor && *pCursor != ' '; ++pCursor)
|
||||
++m_PlaceholderLength;
|
||||
|
||||
str_copy(m_aCompletionBuffer, m_Input.GetString() + m_PlaceholderOffset, minimum(static_cast<int>(sizeof(m_aCompletionBuffer)), m_PlaceholderLength + 1));
|
||||
str_truncate(m_aCompletionBuffer, sizeof(m_aCompletionBuffer), m_Input.GetString() + m_PlaceholderOffset, m_PlaceholderLength);
|
||||
}
|
||||
|
||||
if(m_aCompletionBuffer[0] == '/')
|
||||
|
@ -372,7 +372,7 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
{
|
||||
char aBuf[256];
|
||||
// add part before the name
|
||||
str_copy(aBuf, m_Input.GetString(), minimum(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset + 1));
|
||||
str_truncate(aBuf, sizeof(aBuf), m_Input.GetString(), m_PlaceholderOffset);
|
||||
|
||||
// add the command
|
||||
str_append(aBuf, "/", sizeof(aBuf));
|
||||
|
@ -448,7 +448,7 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
{
|
||||
char aBuf[256];
|
||||
// add part before the name
|
||||
str_copy(aBuf, m_Input.GetString(), minimum(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset + 1));
|
||||
str_truncate(aBuf, sizeof(aBuf), m_Input.GetString(), m_PlaceholderOffset);
|
||||
|
||||
// add the name
|
||||
str_append(aBuf, pCompletionString, sizeof(aBuf));
|
||||
|
@ -591,11 +591,11 @@ void CChat::StoreSave(const char *pText)
|
|||
return;
|
||||
|
||||
char aName[16];
|
||||
str_copy(aName, pStart + 27, minimum(static_cast<size_t>(pMid - pStart - 26), sizeof(aName)));
|
||||
str_truncate(aName, sizeof(aName), pStart + 27, pMid - pStart - 27);
|
||||
|
||||
char aSaveCode[64];
|
||||
|
||||
str_copy(aSaveCode, pMid + 13, minimum(static_cast<size_t>((pOn ? pOn : pEnd) - pMid - 12), sizeof(aSaveCode)));
|
||||
str_truncate(aSaveCode, sizeof(aSaveCode), pMid + 13, (pOn ? pOn : pEnd) - pMid - 13);
|
||||
|
||||
char aTimestamp[20];
|
||||
str_timestamp_format(aTimestamp, sizeof(aTimestamp), FORMAT_SPACE);
|
||||
|
|
|
@ -764,7 +764,7 @@ int CMenus::DemolistFetchCallback(const char *pName, time_t Date, int IsDir, int
|
|||
}
|
||||
else
|
||||
{
|
||||
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), str_length(pName) - 4));
|
||||
str_truncate(Item.m_aName, sizeof(Item.m_aName), pName, str_length(pName) - 5);
|
||||
Item.m_InfosLoaded = false;
|
||||
Item.m_Date = Date;
|
||||
}
|
||||
|
|
|
@ -176,13 +176,12 @@ void CRaceDemo::StopRecord(int Time)
|
|||
int CRaceDemo::RaceDemolistFetchCallback(const char *pName, time_t Date, int IsDir, int StorageType, void *pUser)
|
||||
{
|
||||
CDemoListParam *pParam = (CDemoListParam *)pUser;
|
||||
int Length = str_length(pName);
|
||||
int MapLen = str_length(pParam->pMap);
|
||||
if(IsDir || !str_endswith(pName, ".demo") || !str_startswith(pName, pParam->pMap) || pName[MapLen] != '_')
|
||||
return 0;
|
||||
|
||||
CDemoItem Item;
|
||||
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), Length - 4));
|
||||
str_truncate(Item.m_aName, sizeof(Item.m_aName), pName, str_length(pName) - 5);
|
||||
|
||||
const char *pTime = Item.m_aName + MapLen + 1;
|
||||
const char *pTEnd = pTime;
|
||||
|
|
|
@ -4261,7 +4261,6 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
|
|||
static int EditorListdirCallback(const char *pName, int IsDir, int StorageType, void *pUser)
|
||||
{
|
||||
CEditor *pEditor = (CEditor *)pUser;
|
||||
int Length = str_length(pName);
|
||||
if((pName[0] == '.' && (pName[1] == 0 ||
|
||||
(pName[1] == '.' && pName[2] == 0 && (!str_comp(pEditor->m_pFileDialogPath, "maps") || !str_comp(pEditor->m_pFileDialogPath, "mapres"))))) ||
|
||||
(!IsDir && ((pEditor->m_FileDialogFileType == CEditor::FILETYPE_MAP && !str_endswith(pName, ".map")) ||
|
||||
|
@ -4275,10 +4274,8 @@ static int EditorListdirCallback(const char *pName, int IsDir, int StorageType,
|
|||
str_format(Item.m_aName, sizeof(Item.m_aName), "%s/", pName);
|
||||
else
|
||||
{
|
||||
if(pEditor->m_FileDialogFileType == CEditor::FILETYPE_SOUND)
|
||||
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), Length - 4));
|
||||
else
|
||||
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), Length - 3));
|
||||
int LenEnding = pEditor->m_FileDialogFileType == CEditor::FILETYPE_SOUND ? 5 : 4;
|
||||
str_truncate(Item.m_aName, sizeof(Item.m_aName), pName, str_length(pName) - LenEnding);
|
||||
}
|
||||
Item.m_IsDir = IsDir != 0;
|
||||
Item.m_IsLink = false;
|
||||
|
|
Loading…
Reference in a new issue