oomd: review follow ups to #20020

This commit is contained in:
Anita Zhang
2021-07-02 09:26:40 +02:00
committed by Lennart Poettering
parent 49590d67c9
commit e82acab4db
3 changed files with 27 additions and 12 deletions
+11 -3
View File
@@ -201,7 +201,8 @@ int procfs_cpu_get_usage(nsec_t *ret) {
return 0;
}
int convert_meminfo_value_to_uint64_bytes(char *word, uint64_t *ret) {
int convert_meminfo_value_to_uint64_bytes(const char *word, uint64_t *ret) {
_cleanup_free_ char *w = NULL;
char *digits, *e;
uint64_t v;
size_t n;
@@ -210,9 +211,13 @@ int convert_meminfo_value_to_uint64_bytes(char *word, uint64_t *ret) {
assert(word);
assert(ret);
w = strdup(word);
if (!w)
return -ENOMEM;
/* Determine length of numeric value */
n = strspn(word, WHITESPACE);
digits = word + n;
n = strspn(w, WHITESPACE);
digits = w + n;
n = strspn(digits, DIGITS);
if (n == 0)
return -EINVAL;
@@ -232,6 +237,9 @@ int convert_meminfo_value_to_uint64_bytes(char *word, uint64_t *ret) {
if (v == UINT64_MAX)
return -EINVAL;
if (v > UINT64_MAX/1024)
return -EOVERFLOW;
*ret = v * 1024U;
return 0;
}
+1 -2
View File
@@ -16,5 +16,4 @@ static inline int procfs_memory_get_used(uint64_t *ret) {
return procfs_memory_get(NULL, ret);
}
/* This function destroys "word" (it'll be truncated to perform conversion) */
int convert_meminfo_value_to_uint64_bytes(char *word, uint64_t *ret);
int convert_meminfo_value_to_uint64_bytes(const char *word, uint64_t *ret);