Loco string argument safe strlen
| 206 | |
| 207 | // Loco string argument safe strlen |
| 208 | size_t locoStrlen(const char* buffer) |
| 209 | { |
| 210 | if (buffer == nullptr) |
| 211 | { |
| 212 | return 0; |
| 213 | } |
| 214 | auto* ptr = buffer; |
| 215 | while (*ptr != '\0') |
| 216 | { |
| 217 | const auto ch = *ptr++; |
| 218 | if (ch >= ControlCodes::oneArgBegin && ch < ControlCodes::oneArgEnd) |
| 219 | { |
| 220 | ptr++; |
| 221 | } |
| 222 | else if (ch >= ControlCodes::twoArgBegin && ch < ControlCodes::twoArgEnd) |
| 223 | { |
| 224 | ptr += 2; |
| 225 | } |
| 226 | else if (ch >= ControlCodes::fourArgBegin && ch < ControlCodes::fourArgEnd) |
| 227 | { |
| 228 | ptr += 4; |
| 229 | } |
| 230 | } |
| 231 | return ptr - buffer; |
| 232 | } |
| 233 | |
| 234 | // Loco string argument safe strlen_s |
| 235 | size_t locoStrlenS(const char* buffer, std::size_t size) |
no outgoing calls
no test coverage detected