From f94d476cf2ec4dd65b4eaed01b2b71ac3c5dbf32 Mon Sep 17 00:00:00 2001 From: def Date: Sat, 10 Oct 2020 12:14:07 +0200 Subject: [PATCH] Don't divide by 0 in LoadSkin src/game/client/components/skins.cpp:142:14: runtime error: -nan is outside the range of representable values of type 'int' #0 0x55b6bd0f49e1 in CSkins::LoadSkin(char const*, char const*, int, int*) /media/ddnet/src/game/client/components/skins.cpp:142:14 #1 0x55b6bd0f0942 in CSkins::SkinScan(char const*, int, int, void*) /media/ddnet/src/game/client/components/skins.cpp:55:16 #2 0x55b6bcb33928 in fs_listdir /media/ddnet/src/base/system.c:2033:6 #3 0x55b6bcb04024 in CStorage::ListDirectory(int, char const*, int (*)(char const*, int, int, void*), void*) /media/ddnet/src/engine/shared/storage.cpp:316:5 #4 0x55b6bd0f9e2f in CSkins::Refresh() /media/ddnet/src/game/client/components/skins.cpp:222:13 #5 0x55b6bd0f6e33 in CSkins::OnInit() /media/ddnet/src/game/client/components/skins.cpp:194:2 #6 0x55b6bd14c63f in CGameClient::OnInit() /media/ddnet/src/game/client/gameclient.cpp:322:28 #7 0x55b6bcc5f9f8 in CClient::Run() /media/ddnet/src/engine/client/client.cpp:3089:16 #8 0x55b6bcc84b7e in main /media/ddnet/src/engine/client/client.cpp:4341:11 #9 0x7f1144ded151 in __libc_start_main (/usr/lib/libc.so.6+0x28151) #10 0x55b6bc9d1e0d in _start (/media/ddnet/DDNet+0x705e0d) --- src/game/client/components/skins.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 44f761e8f..03ce42626 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -138,8 +138,12 @@ int CSkins::LoadSkin(const char *pName, const char *pPath, int DirType, int *pGe for(int x = 0; x < BodySize; x++) { int v = d[y * Pitch + x * 4]; - if(v <= OrgWeight) + if(OrgWeight == 0) + v = 0; + else if(v <= OrgWeight) v = (int)(((v / (float)OrgWeight) * NewWeight)); + else if(InvOrgWeight == 0) + v = NewWeight; else v = (int)(((v - OrgWeight) / (float)InvOrgWeight) * InvNewWeight + NewWeight); d[y * Pitch + x * 4] = v;