mirror of
https://github.com/isc-projects/bind9.git
synced 2026-03-10 18:28:43 -04:00
4740. [cleanup] Avoid triggering format-truncated warnings. [RT #46107]
This commit is contained in:
parent
62cce53589
commit
d71d41341d
2 changed files with 48 additions and 18 deletions
2
CHANGES
2
CHANGES
|
|
@ -1,3 +1,5 @@
|
|||
4740. [cleanup] Avoid triggering format-truncated warnings. [RT #46107]
|
||||
|
||||
4739. [cleanup] Address clang static analysis warnings. [RT #45952]
|
||||
|
||||
4738. [port] win32: strftime mishandles %Z. [RT #46039]
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <isc/ht.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
static void *
|
||||
|
|
@ -50,11 +51,12 @@ static void test_ht_full(int bits, int count) {
|
|||
isc_ht_init(&ht, mctx, bits);
|
||||
for (i = 1; i < count; i++) {
|
||||
/*
|
||||
* Note that the string we're snprintfing is always > 16 bytes
|
||||
* so we are always filling the key.
|
||||
* Note: snprintf() is followed with strlcat()
|
||||
* to ensure we are always filling the 16 byte key.
|
||||
*/
|
||||
unsigned char key[16];
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
@ -62,7 +64,8 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(i, (isc_int64_t) f);
|
||||
|
|
@ -70,14 +73,20 @@ static void test_ht_full(int bits, int count) {
|
|||
|
||||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_EXISTS);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
char key[64];
|
||||
snprintf((char *)key, 64, "%lld key of a str hashtable!!", i);
|
||||
/*
|
||||
* Note: the key size is now strlen(key) which is bigger
|
||||
* then the keys added above.
|
||||
*/
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, (const unsigned char *) key,
|
||||
strlen(key), (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
|
@ -86,7 +95,11 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 16, "%lld KEY of a raw hashtable!!", i);
|
||||
/*
|
||||
* Note: case of KEY is now in capitals,
|
||||
*/
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " KEY of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(f, NULL);
|
||||
|
|
@ -95,7 +108,8 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
char key[64];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 64, "%lld key of a str hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, (const unsigned char *) key,
|
||||
strlen(key), &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
|
@ -105,7 +119,8 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_delete(ht, key, 16);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
|
|
@ -115,7 +130,11 @@ static void test_ht_full(int bits, int count) {
|
|||
|
||||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
snprintf((char *)key, 16, "%lld KEY of a raw hashtable!!", i);
|
||||
/*
|
||||
* Note: upper case KEY.
|
||||
*/
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " KEY of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
@ -123,7 +142,8 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
char key[64];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 64, "%lld key of a str hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_delete(ht, (const unsigned char *) key,
|
||||
strlen(key));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
|
@ -137,7 +157,11 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 16, "%lld KEY of a raw hashtable!!", i);
|
||||
/*
|
||||
* Note: case of KEY is now in capitals,
|
||||
*/
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " KEY of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(i, (isc_int64_t) f);
|
||||
|
|
@ -146,7 +170,8 @@ static void test_ht_full(int bits, int count) {
|
|||
for (i = 1; i < count; i++) {
|
||||
unsigned char key[16];
|
||||
void *f = NULL;
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(f, NULL);
|
||||
|
|
@ -181,7 +206,8 @@ static void test_ht_iterator() {
|
|||
* Note that the string we're snprintfing is always > 16 bytes
|
||||
* so we are always filling the key.
|
||||
*/
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", i);
|
||||
snprintf((char *)key, sizeof(key), "%lld", i);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
@ -197,7 +223,8 @@ static void test_ht_iterator() {
|
|||
isc_ht_iter_current(iter, (void**) &v);
|
||||
isc_ht_iter_currentkey(iter, &tkey, &tksize);
|
||||
ATF_REQUIRE_EQ(tksize, 16);
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", v);
|
||||
snprintf((char *)key, sizeof(key), "%lld", v);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
ATF_REQUIRE_EQ(memcmp(key, tkey, 16), 0);
|
||||
walked++;
|
||||
}
|
||||
|
|
@ -211,7 +238,8 @@ static void test_ht_iterator() {
|
|||
isc_ht_iter_current(iter, (void**) &v);
|
||||
isc_ht_iter_currentkey(iter, &tkey, &tksize);
|
||||
ATF_REQUIRE_EQ(tksize, 16);
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", v);
|
||||
snprintf((char *)key, sizeof(key), "%lld", v);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
ATF_REQUIRE_EQ(memcmp(key, tkey, 16), 0);
|
||||
if (v % 2 == 0) {
|
||||
result = isc_ht_iter_delcurrent_next(iter);
|
||||
|
|
@ -230,7 +258,8 @@ static void test_ht_iterator() {
|
|||
isc_ht_iter_current(iter, (void**) &v);
|
||||
isc_ht_iter_currentkey(iter, &tkey, &tksize);
|
||||
ATF_REQUIRE_EQ(tksize, 16);
|
||||
snprintf((char *)key, 16, "%lld key of a raw hashtable!!", v);
|
||||
snprintf((char *)key, sizeof(key), "%lld", v);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
ATF_REQUIRE_EQ(memcmp(key, tkey, 16), 0);
|
||||
if (v % 2 == 1) {
|
||||
result = isc_ht_iter_delcurrent_next(iter);
|
||||
|
|
@ -322,4 +351,3 @@ ATF_TP_ADD_TCS(tp) {
|
|||
ATF_TP_ADD_TC(tp, isc_ht_iterator);
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue