Skip to content

Commit

Permalink
Fix dse_yaml_get_uint() and dse_yaml_get_int().
Browse files Browse the repository at this point in the history
Signed-off-by: Rule Timothy (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Apr 3, 2024
1 parent 2d99dd9 commit 060a843
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions dse/clib/util/yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ DLL_PUBLIC int dse_yaml_get_uint(
if (_scalar == NULL) return EINVAL;
/* Integer? */
errno = 0;
unsigned int _uint = strtol(_scalar, NULL, 10);
if (errno == 0) {
*value = _uint;
char* endptr = NULL;
int _int = strtol(_scalar, &endptr, 10);
if (errno == 0 && _scalar != endptr && *endptr == '\0' && _int >= 0) {
*value = (unsigned int)_int;
return 0;
}
/* Fallback to bool? */
Expand Down Expand Up @@ -256,8 +257,9 @@ DLL_PUBLIC int dse_yaml_get_int(YamlNode* node, const char* name, int* value)
return EINVAL;
/* Integer? */
errno = 0;
int _int = strtol(_scalar, NULL, 10);
if (errno == 0) {
char* endptr = NULL;
int _int = strtol(_scalar, &endptr, 10);
if (errno == 0 && _scalar != endptr && *endptr == '\0') {
*value = _int;
return 0;
}
Expand Down

0 comments on commit 060a843

Please sign in to comment.