| 69 | static_assert(std::numeric_limits<char>::is_signed, "char must be signed for StrToInts to work correctly"); |
| 70 | |
| 71 | void 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 | |
| 91 | bool IntsToStr(const int *pInts, size_t NumInts, char *pStr, size_t StrSize) |
| 92 | { |