diff --git a/strbuf.h b/strbuf.h index b4b6c8ce..f9c373c9 100644 --- a/strbuf.h +++ b/strbuf.h @@ -76,6 +76,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include #include #include #include @@ -442,15 +443,15 @@ __STRBUF_INLINE size_t strbuf_len(const_strbuf sb) { } -/** Return remaining space in the strbuf, not counting the terminating nul. Return - * the maximum possible size_t value if the strbuf is of undefined size. +/** Return remaining space in the strbuf, not counting the terminating nul. + * Return SIZE_MAX if the strbuf is of undefined size. * * Invariant: strbuf_size(sb) == -1 || strbuf_remaining(sb) == strbuf_size(sb) - strbuf_len(sb) * * @author Andrew Bettison */ __STRBUF_INLINE size_t strbuf_remaining(const_strbuf sb) { - return sb->end ? sb->end - strbuf_end(sb) : ~(size_t)0; + return !sb->end ? SIZE_MAX : sb->current > sb->end ? 0 : (size_t)(sb->end - sb->current); } /** Return the number of chars appended to the strbuf so far, not counting the diff --git a/strbuf_helpers.c b/strbuf_helpers.c index e79728e1..e2ed5ec3 100644 --- a/strbuf_helpers.c +++ b/strbuf_helpers.c @@ -393,7 +393,7 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t default: { strbuf_append_socket_domain(sb, addr->sa_family); size_t len = addrlen > sizeof addr->sa_family ? addrlen - sizeof addr->sa_family : 0; - int i; + unsigned i; for (i = 0; i < len; ++i) { strbuf_putc(sb, i ? ',' : ':'); strbuf_sprintf(sb, "%02x", addr->sa_data[i]);