Common string checks used in libsysutil functions
| 402 | |
| 403 | // Common string checks used in libsysutil functions |
| 404 | s32 sysutil_check_name_string(const char* src, s32 minlen, s32 maxlen) |
| 405 | { |
| 406 | s32 lastpos; |
| 407 | |
| 408 | if (g_ps3_process_info.sdk_ver > 0x36FFFF) |
| 409 | { |
| 410 | // Limit null terminator boundary to before buffer max size |
| 411 | lastpos = std::max(maxlen - 1, 0); |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | // Limit null terminator boundary to one after buffer max size |
| 416 | lastpos = maxlen; |
| 417 | } |
| 418 | |
| 419 | char cur = src[0]; |
| 420 | |
| 421 | if (cur == '_') |
| 422 | { |
| 423 | // Invalid character at start |
| 424 | return -1; |
| 425 | } |
| 426 | |
| 427 | for (s32 index = 0;; cur = src[++index]) |
| 428 | { |
| 429 | if (cur == '\0' || index == maxlen) |
| 430 | { |
| 431 | if (minlen > index || (maxlen == index && src[lastpos])) |
| 432 | { |
| 433 | // String length is invalid |
| 434 | return -2; |
| 435 | } |
| 436 | |
| 437 | // OK |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | if (cur >= 'A' && cur <= 'Z') |
| 442 | { |
| 443 | continue; |
| 444 | } |
| 445 | |
| 446 | if (cur >= '0' && cur <= '9') |
| 447 | { |
| 448 | continue; |
| 449 | } |
| 450 | |
| 451 | if (cur == '-' || cur == '_') |
| 452 | { |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | // Invalid character found |
| 457 | return -1; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | error_code _cellSysutilGetSystemParamInt() |
no test coverage detected