MCPcopy Create free account
hub / github.com/ddnet/ddnet / StrToInts

Function StrToInts

src/game/gamecore.cpp:71–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69static_assert(std::numeric_limits<char>::is_signed, "char must be signed for StrToInts to work correctly");
70
71void StrToInts(int *pInts, size_t NumInts, const char *pStr)
72{
73 dbg_assert(NumInts > 0, "StrToInts: NumInts invalid");
74 const size_t StrSize = str_length(pStr) + 1;
75 dbg_assert(StrSize <= NumInts * sizeof(int), "StrToInts: string truncated");
76
77 for(size_t i = 0; i < NumInts; i++)
78 {
79 // Copy to temporary buffer to ensure we don't read past the end of the input string
80 char aBuf[sizeof(int)] = {0, 0, 0, 0};
81 for(size_t c = 0; c < sizeof(int) && i * sizeof(int) + c < StrSize; c++)
82 {
83 aBuf[c] = pStr[i * sizeof(int) + c];
84 }
85 pInts[i] = ((aBuf[0] + 128) << 24) | ((aBuf[1] + 128) << 16) | ((aBuf[2] + 128) << 8) | (aBuf[3] + 128);
86 }
87 // Last byte is always zero and unused in this format
88 pInts[NumInts - 1] &= 0xFFFFFF00;
89}
90
91bool IntsToStr(const int *pInts, size_t NumInts, char *pStr, size_t StrSize)
92{

Callers 7

TranslateSnapMethod · 0.85
OnDemoRecSnap7Method · 0.85
SetGhostSkinDataMethod · 0.85
SaveMethod · 0.85
SnapMethod · 0.85
FakeSnapMethod · 0.85
TESTFunction · 0.85

Calls 1

str_lengthFunction · 0.85

Tested by 1

TESTFunction · 0.68