3532: Fix crash on namechange (fixes #3444) r=heinrich5991 a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [x] Tested in combination with possibly related configuration options
- [x] Written a unit test if it works standalone, system.c especially
- [x] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [x] 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: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-01-22 18:49:15 +00:00 committed by GitHub
commit 7f4ec45e9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 1 deletions

View file

@ -631,7 +631,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
if(Text)
{
int Offset = str_length(pStr);
int CharsLeft = StrSize - Offset - 1;
int CharsLeft = StrSize - Offset;
char *pCur = pStr + Offset;
str_utf8_copy(pCur, Text, CharsLeft);
for(int i = 0; i < CharsLeft; i++)

View file

@ -217,6 +217,8 @@ TEST(Str, StrCopyNum)
EXPECT_STREQ(aBuf, "Foobar");
str_utf8_truncate(aBuf, sizeof(aBuf), foo, 7);
EXPECT_STREQ(aBuf, "Foobaré");
str_utf8_truncate(aBuf, sizeof(aBuf), foo, 0);
EXPECT_STREQ(aBuf, "");
char aBuf2[8];
str_utf8_truncate(aBuf2, sizeof(aBuf2), foo, 7);

View file

@ -79,4 +79,5 @@ TEST(Thread, Lock)
void *pThread = thread_init(LockThread, &Lock, "lock");
lock_unlock(Lock);
thread_wait(pThread);
lock_destroy(Lock);
}