diff options
author | Zhanna Tsitkov <tsitkova@mit.edu> | 2013-09-19 10:00:41 -0400 |
---|---|---|
committer | Zhanna Tsitkov <tsitkova@mit.edu> | 2013-09-19 10:00:41 -0400 |
commit | 2d832972094477cd9fe6b97991e62b00c7174d8a (patch) | |
tree | 4da554dd88346b2c4ae7d5bc9977ee881ad454f8 /src/util/support | |
parent | 3d359e42de2975eddcece76fb0381000c23daba5 (diff) | |
download | krb5-2d832972094477cd9fe6b97991e62b00c7174d8a.tar.gz krb5-2d832972094477cd9fe6b97991e62b00c7174d8a.tar.xz krb5-2d832972094477cd9fe6b97991e62b00c7174d8a.zip |
Use macros instead of magic numbers in json.c
Avoid using "magic numbers" for better maintainability.
Diffstat (limited to 'src/util/support')
-rw-r--r-- | src/util/support/json.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/util/support/json.c b/src/util/support/json.c index b99fabd49..d23267c17 100644 --- a/src/util/support/json.c +++ b/src/util/support/json.c @@ -79,6 +79,7 @@ #include <k5-buf.h> #define MAX_DECODE_DEPTH 64 +#define MIN_ALLOC_SLOT 16 typedef void (*type_dealloc_fn)(void *val); @@ -235,10 +236,10 @@ k5_json_array_add(k5_json_array array, k5_json_value val) size_t new_alloc; if (array->len >= array->allocated) { - /* Increase the number of slots by 50% (16 slots minimum). */ + /* Increase the number of slots by 50% (MIN_ALLOC_SLOT minimum). */ new_alloc = array->len + 1 + (array->len >> 1); - if (new_alloc < 16) - new_alloc = 16; + if (new_alloc < MIN_ALLOC_SLOT) + new_alloc = MIN_ALLOC_SLOT; ptr = realloc(array->values, new_alloc * sizeof(*array->values)); if (ptr == NULL) return ENOMEM; @@ -452,10 +453,10 @@ k5_json_object_set(k5_json_object obj, const char *key, k5_json_value val) return 0; if (obj->len >= obj->allocated) { - /* Increase the number of slots by 50% (16 slots minimum). */ + /* Increase the number of slots by 50% (MIN_ALLOC_SLOT minimum). */ new_alloc = obj->len + 1 + (obj->len >> 1); - if (new_alloc < 16) - new_alloc = 16; + if (new_alloc < MIN_ALLOC_SLOT) + new_alloc = MIN_ALLOC_SLOT; ptr = realloc(obj->entries, new_alloc * sizeof(*obj->entries)); if (ptr == NULL) return ENOMEM; |