From f100ea0ff44e173299e8f691115b9e7ce68d422b Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 22 Apr 2019 17:52:23 -0400 Subject: [PATCH] Add constant for maximum buffer sizes required by cvt*() functions. Also update Variant to use cvt*() in all cases. Variant was written before these functions were available and not all cases were updated. --- doc/xml/release.xml | 4 ++++ src/common/io/tls/client.c | 2 +- src/common/type/convert.h | 6 ++++++ src/common/type/variant.c | 23 ++++++++++++----------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index a8df74b4b..a3290c053 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -37,6 +37,10 @@

varNewKv() accepts a KeyValue object rather than creating one.

+ +

Add constant for maximum buffer sizes required by cvt*() functions.

+
+

Add true and false String constants.

diff --git a/src/common/io/tls/client.c b/src/common/io/tls/client.c index 23cc82003..9063bbf96 100644 --- a/src/common/io/tls/client.c +++ b/src/common/io/tls/client.c @@ -298,7 +298,7 @@ tlsClientOpen(TlsClient *this) hints.ai_protocol = IPPROTO_TCP; // Convert the port to a zero-terminated string for use with getaddrinfo() - char port[32]; + char port[CVT_BASE10_BUFFER_SIZE]; cvtUIntToZ(this->port, port, sizeof(port)); // Get an address for the host. We are only going to try the first address returned. diff --git a/src/common/type/convert.h b/src/common/type/convert.h index ed5986656..1ed04d2c2 100644 --- a/src/common/type/convert.h +++ b/src/common/type/convert.h @@ -7,6 +7,12 @@ Convert Base Data Types #include #include +/*********************************************************************************************************************************** +Required buffer sizes +***********************************************************************************************************************************/ +#define CVT_BOOL_BUFFER_SIZE 6 +#define CVT_BASE10_BUFFER_SIZE 64 + /*********************************************************************************************************************************** Functions ***********************************************************************************************************************************/ diff --git a/src/common/type/variant.c b/src/common/type/variant.c index 74b2f3035..a79bf4298 100644 --- a/src/common/type/variant.c +++ b/src/common/type/variant.c @@ -1080,27 +1080,22 @@ varStrForce(const Variant *this) { case varTypeBool: { - char working[6]; - - cvtBoolToZ(varBool(this), working, sizeof(working)); - result = strNew(working); - + result = strNew(cvtBoolToConstZ(varBool(this))); break; } case varTypeDouble: { - char working[64]; + char working[CVT_BASE10_BUFFER_SIZE]; cvtDoubleToZ(varDbl(this), working, sizeof(working)); result = strNew(working); - break; } case varTypeInt: { - char working[64]; + char working[CVT_BASE10_BUFFER_SIZE]; cvtIntToZ(varInt(this), working, sizeof(working)); result = strNew(working); @@ -1109,7 +1104,7 @@ varStrForce(const Variant *this) case varTypeInt64: { - char working[64]; + char working[CVT_BASE10_BUFFER_SIZE]; cvtInt64ToZ(varInt64(this), working, sizeof(working)); result = strNew(working); @@ -1124,13 +1119,19 @@ varStrForce(const Variant *this) case varTypeUInt: { - result = strNewFmt("%u", varUInt(this)); + char working[CVT_BASE10_BUFFER_SIZE]; + + cvtUIntToZ(varUInt(this), working, sizeof(working)); + result = strNew(working); break; } case varTypeUInt64: { - result = strNewFmt("%" PRIu64, varUInt64(this)); + char working[CVT_BASE10_BUFFER_SIZE]; + + cvtUInt64ToZ(varUInt64(this), working, sizeof(working)); + result = strNew(working); break; }