diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-27 12:16:47 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-27 12:16:47 +0100 |
| commit | c950a0a70d37f962bbef66221ff0a23cad450195 (patch) | |
| tree | 026e2c8269dc0dda8daf1dc942526c3bfc63245d | |
| parent | 25d16ff06c2551ed090c2847efdc819303e577f3 (diff) | |
| download | malloc-c950a0a70d37f962bbef66221ff0a23cad450195.tar.gz malloc-c950a0a70d37f962bbef66221ff0a23cad450195.zip | |
Fix stale filename comment, const qualifier, and int-to-size_t casts
- test_preload.c: @file main.c -> @file test_preload.c
- show_alloc_mem.c, test_preload.c: hex array -> static const
- show_alloc_mem.c, test_preload.c, test_random.c: use size_t
for sizeof-derived indices instead of casting to int
| -rw-r--r-- | src/show_alloc_mem.c | 6 | ||||
| -rw-r--r-- | tests/src/test_preload.c | 10 | ||||
| -rw-r--r-- | tests/src/test_random.c | 6 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/show_alloc_mem.c b/src/show_alloc_mem.c index 6fd5e37..5ffdecc 100644 --- a/src/show_alloc_mem.c +++ b/src/show_alloc_mem.c @@ -10,13 +10,13 @@ static void _s_put_ptr (void *ptr) { - const char hex[] = "0123456789abcdef"; + static const char hex[] = "0123456789abcdef"; char buf[20]; unsigned long value; - int i; + size_t i; value = (unsigned long)ptr; - i = (int)sizeof (buf); + i = sizeof (buf); while (value) { buf[--i] = hex[value % 16]; diff --git a/tests/src/test_preload.c b/tests/src/test_preload.c index 0ded605..7369035 100644 --- a/tests/src/test_preload.c +++ b/tests/src/test_preload.c @@ -1,5 +1,5 @@ /** - * @file main.c + * @file test_preload.c * @brief Smoke test — call malloc once and print the returned pointer. * * Uses write(2) instead of printf to avoid stdio calling malloc @@ -13,17 +13,17 @@ static void _s_put_ptr (void *ptr) { - const char hex[] = "0123456789abcdef"; + static const char hex[] = "0123456789abcdef"; char buf[20]; unsigned long v = (unsigned long)ptr; - int i; + size_t i; if (!ptr) { write (1, "(nil)", 5); return; } - i = (int)sizeof (buf); + i = sizeof (buf); while (v) { buf[--i] = hex[v % 16]; @@ -31,7 +31,7 @@ _s_put_ptr (void *ptr) } buf[--i] = 'x'; buf[--i] = '0'; - write (1, buf + i, (size_t)(sizeof (buf) - i)); + write (1, buf + i, sizeof (buf) - i); } int diff --git a/tests/src/test_random.c b/tests/src/test_random.c index 396abf9..89284a0 100644 --- a/tests/src/test_random.c +++ b/tests/src/test_random.c @@ -31,9 +31,9 @@ static void _s_put_nbr (int n) { char buf[12]; - int i; + size_t i; - i = (int)sizeof (buf); + i = sizeof (buf); if (n == 0) buf[--i] = '0'; while (n > 0) @@ -41,7 +41,7 @@ _s_put_nbr (int n) buf[--i] = '0' + (n % 10); n /= 10; } - write (1, buf + i, (size_t)(sizeof (buf) - i)); + write (1, buf + i, sizeof (buf) - i); } static unsigned char |
