Fix -Wsign-compare warnings in strbuf

This commit is contained in:
Andrew Bettison 2013-12-09 16:29:06 +10:30
parent 6b3d4e563f
commit 27b37c143f
2 changed files with 5 additions and 4 deletions

View File

@ -76,6 +76,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
@ -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 <andrew@servalproject.com>
*/
__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

View File

@ -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]);