Skip to content

Commit 22af74e

Browse files
author
Jason Evans
committed
Refactor out signed/unsigned comparisons.
1 parent 434ea64 commit 22af74e

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

include/jemalloc/internal/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ void malloc_write(const char *s);
106106
* malloc_vsnprintf() supports a subset of snprintf(3) that avoids floating
107107
* point math.
108108
*/
109-
int malloc_vsnprintf(char *str, size_t size, const char *format,
109+
size_t malloc_vsnprintf(char *str, size_t size, const char *format,
110110
va_list ap);
111-
int malloc_snprintf(char *str, size_t size, const char *format, ...)
111+
size_t malloc_snprintf(char *str, size_t size, const char *format, ...)
112112
JEMALLOC_FORMAT_PRINTF(3, 4);
113113
void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
114114
const char *format, va_list ap);

src/util.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,9 @@ x2s(uintmax_t x, bool alt_form, bool uppercase, char *s, size_t *slen_p)
314314
return (s);
315315
}
316316

317-
int
317+
size_t
318318
malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
319319
{
320-
int ret;
321320
size_t i;
322321
const char *f;
323322

@@ -585,21 +584,19 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
585584
str[i] = '\0';
586585
else
587586
str[size - 1] = '\0';
588-
assert(i < INT_MAX);
589-
ret = (int)i;
590587

591588
#undef APPEND_C
592589
#undef APPEND_S
593590
#undef APPEND_PADDED_S
594591
#undef GET_ARG_NUMERIC
595-
return (ret);
592+
return (i);
596593
}
597594

598595
JEMALLOC_FORMAT_PRINTF(3, 4)
599-
int
596+
size_t
600597
malloc_snprintf(char *str, size_t size, const char *format, ...)
601598
{
602-
int ret;
599+
size_t ret;
603600
va_list ap;
604601

605602
va_start(ap, format);

test/src/timer.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen)
3232
uint64_t t0 = timer_usec(a);
3333
uint64_t t1 = timer_usec(b);
3434
uint64_t mult;
35-
unsigned i = 0;
36-
unsigned j;
37-
int n;
35+
size_t i = 0;
36+
size_t j, n;
3837

3938
/* Whole. */
4039
n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1);

test/unit/bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ TEST_BEGIN(test_bitmap_sfu)
101101
bitmap_info_t binfo;
102102
bitmap_info_init(&binfo, i);
103103
{
104-
ssize_t j;
104+
size_t j;
105105
bitmap_t *bitmap = (bitmap_t *)malloc(
106106
bitmap_size(&binfo));
107107
bitmap_init(bitmap, &binfo);
@@ -119,7 +119,7 @@ TEST_BEGIN(test_bitmap_sfu)
119119
* Iteratively unset bits starting at the end, and
120120
* verify that bitmap_sfu() reaches the unset bits.
121121
*/
122-
for (j = i - 1; j >= 0; j--) {
122+
for (j = i - 1; j < i; j--) { /* (i..0] */
123123
bitmap_unset(bitmap, &binfo, j);
124124
assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
125125
"First unset bit should the bit previously "

test/unit/util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ TEST_BEGIN(test_malloc_snprintf_truncated)
160160
{
161161
#define BUFLEN 15
162162
char buf[BUFLEN];
163-
int result;
163+
size_t result;
164164
size_t len;
165165
#define TEST(expected_str_untruncated, ...) do { \
166166
result = malloc_snprintf(buf, len, __VA_ARGS__); \
167167
assert_d_eq(strncmp(buf, expected_str_untruncated, len-1), 0, \
168168
"Unexpected string inequality (\"%s\" vs \"%s\")", \
169169
buf, expected_str_untruncated); \
170-
assert_d_eq(result, strlen(expected_str_untruncated), \
170+
assert_zu_eq(result, strlen(expected_str_untruncated), \
171171
"Unexpected result"); \
172172
} while (0)
173173

@@ -193,11 +193,11 @@ TEST_BEGIN(test_malloc_snprintf)
193193
{
194194
#define BUFLEN 128
195195
char buf[BUFLEN];
196-
int result;
196+
size_t result;
197197
#define TEST(expected_str, ...) do { \
198198
result = malloc_snprintf(buf, sizeof(buf), __VA_ARGS__); \
199199
assert_str_eq(buf, expected_str, "Unexpected output"); \
200-
assert_d_eq(result, strlen(expected_str), "Unexpected result"); \
200+
assert_zu_eq(result, strlen(expected_str), "Unexpected result");\
201201
} while (0)
202202

203203
TEST("hello", "hello");

0 commit comments

Comments
 (0)