Option: improve reliablity

This commit is contained in:
李通洲
2026-04-29 23:52:38 +08:00
committed by Carter Li
parent ab5cf94099
commit e91f62aa70
+10 -6
View File
@@ -3,8 +3,12 @@
#include "common/color.h"
#include "common/stringUtils.h"
#include <limits.h>
// Return start position of the inner key if the argument key belongs to the module specified, NULL otherwise
const char* ffOptionTestPrefix(const char* argumentKey, const char* moduleName) {
assert(argumentKey && moduleName);
const char* subKey = argumentKey;
if (!(subKey[0] == '-' && subKey[1] == '-')) {
return NULL;
@@ -47,13 +51,13 @@ uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value) {
}
char* end;
uint32_t num = (uint32_t) strtoul(value, &end, 10);
if (*end != '\0') {
unsigned long num = strtoul(value, &end, 10);
if (value[0] == '-' || *end != '\0' || num > UINT32_MAX) {
fprintf(stderr, "Error: usage: %s <num>\n", argumentKey);
exit(479);
}
return num;
return (uint32_t) num;
}
int32_t ffOptionParseInt32(const char* argumentKey, const char* value) {
@@ -63,13 +67,13 @@ int32_t ffOptionParseInt32(const char* argumentKey, const char* value) {
}
char* end;
int32_t num = (int32_t) strtol(value, &end, 10);
if (*end != '\0') {
long num = strtol(value, &end, 10);
if (*end != '\0' || num < INT32_MIN || num > INT32_MAX) {
fprintf(stderr, "Error: usage: %s <num>\n", argumentKey);
exit(479);
}
return num;
return (int32_t) num;
}
int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]) {