Remove isc_string_printf and isc_string_printf_truncate.
Replace with simple snprintf() as appropriate.
This commit is contained in:
@@ -705,10 +705,11 @@ dns_journal_open(isc_mem_t *mctx, const char *filename, unsigned int mode,
|
||||
if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0)
|
||||
namelen -= 4;
|
||||
|
||||
result = isc_string_printf(backup, sizeof(backup), "%.*s.jbk",
|
||||
(int)namelen, filename);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
result = snprintf(backup, sizeof(backup), "%.*s.jbk",
|
||||
(int)namelen, filename);
|
||||
if (result >= sizeof(backup)) {
|
||||
return ISC_R_NOSPACE;
|
||||
}
|
||||
result = journal_open(mctx, backup, writable, writable,
|
||||
journalp);
|
||||
}
|
||||
@@ -2100,25 +2101,24 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
|
||||
unsigned int size = 0;
|
||||
isc_result_t result;
|
||||
unsigned int indexend;
|
||||
char newname[1024];
|
||||
char backup[1024];
|
||||
char newname[PATH_MAX];
|
||||
char backup[PATH_MAX];
|
||||
isc_boolean_t is_backup = ISC_FALSE;
|
||||
|
||||
REQUIRE(filename != NULL);
|
||||
|
||||
namelen = strlen(filename);
|
||||
if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0)
|
||||
if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0) {
|
||||
namelen -= 4;
|
||||
}
|
||||
|
||||
result = isc_string_printf(newname, sizeof(newname), "%.*s.jnw",
|
||||
(int)namelen, filename);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
result = snprintf(newname, sizeof(newname), "%.*s.jnw",
|
||||
(int)namelen, filename);
|
||||
RUNTIME_CHECK(result < sizeof(newname));
|
||||
|
||||
result = isc_string_printf(backup, sizeof(backup), "%.*s.jbk",
|
||||
(int)namelen, filename);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
result = snprintf(backup, sizeof(backup), "%.*s.jbk",
|
||||
(int)namelen, filename);
|
||||
RUNTIME_CHECK(result < sizeof(backup));
|
||||
|
||||
result = journal_open(mctx, filename, ISC_FALSE, ISC_FALSE, &j1);
|
||||
if (result == ISC_R_NOTFOUND) {
|
||||
|
||||
@@ -258,37 +258,37 @@ reverse_from_address(dns_name_t *tcpself, const isc_netaddr_t *tcpaddr) {
|
||||
switch (tcpaddr->family) {
|
||||
case AF_INET:
|
||||
l = ntohl(tcpaddr->type.in.s_addr);
|
||||
result = isc_string_printf(buf, sizeof(buf),
|
||||
"%lu.%lu.%lu.%lu.IN-ADDR.ARPA.",
|
||||
(l >> 0) & 0xff, (l >> 8) & 0xff,
|
||||
(l >> 16) & 0xff, (l >> 24) & 0xff);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
result = snprintf(buf, sizeof(buf),
|
||||
"%lu.%lu.%lu.%lu.IN-ADDR.ARPA.",
|
||||
(l >> 0) & 0xff, (l >> 8) & 0xff,
|
||||
(l >> 16) & 0xff, (l >> 24) & 0xff);
|
||||
RUNTIME_CHECK(result < sizeof(buf));
|
||||
break;
|
||||
case AF_INET6:
|
||||
ap = tcpaddr->type.in6.s6_addr;
|
||||
result = isc_string_printf(buf, sizeof(buf),
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"IP6.ARPA.",
|
||||
ap[15] & 0x0f, (ap[15] >> 4) & 0x0f,
|
||||
ap[14] & 0x0f, (ap[14] >> 4) & 0x0f,
|
||||
ap[13] & 0x0f, (ap[13] >> 4) & 0x0f,
|
||||
ap[12] & 0x0f, (ap[12] >> 4) & 0x0f,
|
||||
ap[11] & 0x0f, (ap[11] >> 4) & 0x0f,
|
||||
ap[10] & 0x0f, (ap[10] >> 4) & 0x0f,
|
||||
ap[9] & 0x0f, (ap[9] >> 4) & 0x0f,
|
||||
ap[8] & 0x0f, (ap[8] >> 4) & 0x0f,
|
||||
ap[7] & 0x0f, (ap[7] >> 4) & 0x0f,
|
||||
ap[6] & 0x0f, (ap[6] >> 4) & 0x0f,
|
||||
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
|
||||
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
|
||||
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
|
||||
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
|
||||
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
|
||||
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
result = snprintf(buf, sizeof(buf),
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"IP6.ARPA.",
|
||||
ap[15] & 0x0f, (ap[15] >> 4) & 0x0f,
|
||||
ap[14] & 0x0f, (ap[14] >> 4) & 0x0f,
|
||||
ap[13] & 0x0f, (ap[13] >> 4) & 0x0f,
|
||||
ap[12] & 0x0f, (ap[12] >> 4) & 0x0f,
|
||||
ap[11] & 0x0f, (ap[11] >> 4) & 0x0f,
|
||||
ap[10] & 0x0f, (ap[10] >> 4) & 0x0f,
|
||||
ap[9] & 0x0f, (ap[9] >> 4) & 0x0f,
|
||||
ap[8] & 0x0f, (ap[8] >> 4) & 0x0f,
|
||||
ap[7] & 0x0f, (ap[7] >> 4) & 0x0f,
|
||||
ap[6] & 0x0f, (ap[6] >> 4) & 0x0f,
|
||||
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
|
||||
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
|
||||
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
|
||||
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
|
||||
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
|
||||
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
|
||||
RUNTIME_CHECK(result < sizeof(buf));
|
||||
break;
|
||||
default:
|
||||
INSIST(0);
|
||||
@@ -310,27 +310,27 @@ stf_from_address(dns_name_t *stfself, const isc_netaddr_t *tcpaddr) {
|
||||
switch(tcpaddr->family) {
|
||||
case AF_INET:
|
||||
l = ntohl(tcpaddr->type.in.s_addr);
|
||||
result = isc_string_printf(buf, sizeof(buf),
|
||||
"%lx.%lx.%lx.%lx.%lx.%lx.%lx.%lx"
|
||||
"2.0.0.2.IP6.ARPA.",
|
||||
l & 0xf, (l >> 4) & 0xf,
|
||||
(l >> 8) & 0xf, (l >> 12) & 0xf,
|
||||
(l >> 16) & 0xf, (l >> 20) & 0xf,
|
||||
(l >> 24) & 0xf, (l >> 28) & 0xf);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
result = snprintf(buf, sizeof(buf),
|
||||
"%lx.%lx.%lx.%lx.%lx.%lx.%lx.%lx"
|
||||
"2.0.0.2.IP6.ARPA.",
|
||||
l & 0xf, (l >> 4) & 0xf,
|
||||
(l >> 8) & 0xf, (l >> 12) & 0xf,
|
||||
(l >> 16) & 0xf, (l >> 20) & 0xf,
|
||||
(l >> 24) & 0xf, (l >> 28) & 0xf);
|
||||
RUNTIME_CHECK(result < sizeof(buf));
|
||||
break;
|
||||
case AF_INET6:
|
||||
ap = tcpaddr->type.in6.s6_addr;
|
||||
result = isc_string_printf(buf, sizeof(buf),
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.IP6.ARPA.",
|
||||
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
|
||||
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
|
||||
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
|
||||
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
|
||||
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
|
||||
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
result = snprintf(buf, sizeof(buf),
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x."
|
||||
"%x.%x.%x.%x.IP6.ARPA.",
|
||||
ap[5] & 0x0f, (ap[5] >> 4) & 0x0f,
|
||||
ap[4] & 0x0f, (ap[4] >> 4) & 0x0f,
|
||||
ap[3] & 0x0f, (ap[3] >> 4) & 0x0f,
|
||||
ap[2] & 0x0f, (ap[2] >> 4) & 0x0f,
|
||||
ap[1] & 0x0f, (ap[1] >> 4) & 0x0f,
|
||||
ap[0] & 0x0f, (ap[0] >> 4) & 0x0f);
|
||||
RUNTIME_CHECK(result < sizeof(buf));
|
||||
break;
|
||||
default:
|
||||
INSIST(0);
|
||||
|
||||
@@ -32,50 +32,6 @@
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
isc_string_printf(char *target, size_t size, const char *format, ...)
|
||||
ISC_FORMAT_PRINTF(3, 4);
|
||||
/*
|
||||
* Print 'format' to 'target' which is a pointer to a string of at least
|
||||
* 'size' bytes.
|
||||
*
|
||||
* Requires:
|
||||
* 'target' is a pointer to a char[] of at least 'size' bytes.
|
||||
* 'size' an integer > 0.
|
||||
* 'format' == NULL or points to a NUL terminated string.
|
||||
*
|
||||
* Ensures:
|
||||
* If result == ISC_R_SUCCESS
|
||||
* 'target' will be a NUL terminated string of no more
|
||||
* than 'size' bytes (including NUL).
|
||||
*
|
||||
* If result == ISC_R_NOSPACE
|
||||
* 'target' is undefined.
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS -- 'format' was successfully printed to 'target'.
|
||||
* ISC_R_NOSPACE -- 'format' could not be printed to 'target' since it
|
||||
* is too small.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
|
||||
ISC_FORMAT_PRINTF(3, 4);
|
||||
/*
|
||||
* Print 'format' to 'target' which is a pointer to a string of at least
|
||||
* 'size' bytes.
|
||||
*
|
||||
* Requires:
|
||||
* 'target' is a pointer to a char[] of at least 'size' bytes.
|
||||
* 'size' an integer > 0.
|
||||
* 'format' == NULL or points to a NUL terminated string.
|
||||
*
|
||||
* Ensures:
|
||||
* 'target' will be a NUL terminated string of no more
|
||||
* than 'size' bytes (including NUL).
|
||||
*/
|
||||
|
||||
|
||||
char *
|
||||
isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source);
|
||||
/*
|
||||
|
||||
@@ -50,42 +50,6 @@
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
isc_result_t
|
||||
isc_string_printf(char *target, size_t size, const char *format, ...) {
|
||||
va_list args;
|
||||
size_t n;
|
||||
|
||||
REQUIRE(size > 0U);
|
||||
|
||||
va_start(args, format);
|
||||
n = vsnprintf(target, size, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (n >= size) {
|
||||
memset(target, ISC_STRING_MAGIC, size);
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
||||
ENSURE(strlen(target) < size);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
REQUIRE(size > 0U);
|
||||
|
||||
va_start(args, format);
|
||||
/* check return code? */
|
||||
(void)vsnprintf(target, size, format, args);
|
||||
va_end(args);
|
||||
|
||||
ENSURE(strlen(target) < size);
|
||||
}
|
||||
|
||||
char *
|
||||
isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source) {
|
||||
char *target;
|
||||
|
||||
@@ -645,8 +645,6 @@ isc_stdio_sync
|
||||
isc_stdio_tell
|
||||
isc_stdio_write
|
||||
isc_stdtime_get
|
||||
isc_string_printf
|
||||
isc_string_printf_truncate
|
||||
isc_string_regiondup
|
||||
isc_string_separate
|
||||
isc_string_strcasestr
|
||||
|
||||
Reference in New Issue
Block a user