diff options
author | Dmitri Pal <dpal@redhat.com> | 2012-12-23 13:49:56 -0500 |
---|---|---|
committer | Ondrej Kos <okos@redhat.com> | 2013-01-24 08:34:40 +0100 |
commit | 833a46e384828be48c27898e755d6215eb5c4bb8 (patch) | |
tree | eaf34cd463381efc40991151d41d9deec295f704 /dhash/examples/dhash_test.c | |
parent | 57faa64667411a3d8eeeeff62b1e659a94ed29cf (diff) | |
download | ding-libs-833a46e384828be48c27898e755d6215eb5c4bb8.tar.gz ding-libs-833a46e384828be48c27898e755d6215eb5c4bb8.tar.xz ding-libs-833a46e384828be48c27898e755d6215eb5c4bb8.zip |
Replacing sprintf with snprintf
Replaced sprintf in the unit test.
Defined constants for sizes and used them.
Wrpapped lines where noticed that they are longer than 80.
Added comments to the places where sprintf is still used
but it is safe to use.
Diffstat (limited to 'dhash/examples/dhash_test.c')
-rw-r--r-- | dhash/examples/dhash_test.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/dhash/examples/dhash_test.c b/dhash/examples/dhash_test.c index 7b4cbbf..f57bc52 100644 --- a/dhash/examples/dhash_test.c +++ b/dhash/examples/dhash_test.c @@ -26,6 +26,7 @@ #include <getopt.h> #include "dhash.h" +#define BUF_SIZE 1024 #define DEFAULT_MAX_TEST (500) hash_entry_t *iter_result_1 = NULL; hash_entry_t *iter_result_2 = NULL; @@ -54,7 +55,7 @@ const char *error_string(int error) char *key_string(hash_key_t *key) { - static char buf[1024]; + static char buf[BUF_SIZE]; switch(key->type) { case HASH_KEY_ULONG: @@ -72,7 +73,7 @@ char *key_string(hash_key_t *key) char *value_string(hash_value_t *value) { - static char buf[1024]; + static char buf[BUF_SIZE]; switch(value->type) { case HASH_VALUE_UNDEF: @@ -109,7 +110,7 @@ char *value_string(hash_value_t *value) char *entry_string(hash_entry_t *entry) { - static char buf[1024]; + static char buf[BUF_SIZE]; snprintf(buf, sizeof(buf), "[%s] = [%s]", key_string(&entry->key), value_string(&entry->value)); @@ -151,7 +152,7 @@ int main(int argc, char **argv) hash_value_t old_value; hash_value_t new_value; hash_key_t key; - char buf[1024]; + char buf[BUF_SIZE]; hash_table_t *table = NULL; unsigned long callback_count = 0; unsigned long table_size = 0; @@ -259,7 +260,7 @@ int main(int argc, char **argv) * otherwise we'll use an unsigned long as the key */ if (test[i].val & 1) { key.type = HASH_KEY_STRING; - sprintf(buf, "%ld", test[i].val); + snprintf(buf, BUF_SIZE, "%ld", test[i].val); test[i].str = strdup(buf); } } |