Skip to content

Commit 79152fe

Browse files
warnings: clear all -Wpointer-sign / -Wunused-value / -Wunused-variable
A clean rebuild surfaced four warning categories that pre-dated the audit loop. Walking each: - Source/Misra/Sys/Proc.c -- POSIX shim macros (close, dup2, read, write, ...) carried an outer cast '((int)misra_proc_close(fd))'. In statement position 'close(fd);' the cast result is computed and discarded -> -Wunused-value at every callsite. Drop the outer cast; implicit conversion handles the (long -> int/pid_t) at assignment sites that bind the result. - Include/Misra/Types.h -- add a portable UNUSED(x) macro -> '(void)(x)'. Pure C, no compiler dispatch needed, works on MSVC. Used for the next item. - Include/Misra/Std/Allocator.h -- Scope / ScopeWith macros declare MisraScope as a per-iteration for-loop variable that the body MAY not reference (legitimate -- not every Scope user needs the default allocator). GCC -Wunused-variable fired. Read MisraScope through UNUSED() in the loop condition to mark it 'used'. - Include/Misra/Std/Allocator/Budget.h -- the BudgetAllocatorInit designated-initializer chain wrapped the MemSet call as '(MemSet(...), 0)'. The trailing ', 0' was discarded by the outer comma chain -> -Wunused-value. MemSet returns void, which the comma operator accepts in a non-last position; drop the ', 0'. - Source/Misra/Std/Container/Map.c -- after GenericMap.entries went from char * to u8 * in commit 1c5a458, several internal scratch vars (old_entries, new_entries, temp_entry) and the map_copy_into_entry parameter were still typed char *, producing -Wpointer-sign at every read / assignment. Flip them all to u8 * to match the field type. Drops .audit-questions.md item 1 (the Debug.c cascading warnings, which a fresh build confirms are already resolved -- the macro expansion is now well-formed '&((void *[]){(ptr)})[0]' from the commit 88950a9 Map LVAL_AS refactor).
1 parent 4098bbf commit 79152fe

5 files changed

Lines changed: 53 additions & 30 deletions

File tree

Include/Misra/Std/Allocator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ extern "C" {
547547
for (Allocator *name = &UNPL(scope_user).base, \
548548
*MisraScope = &UNPL(scope_internal).base, \
549549
*UNPL(scope_done) = name; \
550-
UNPL(scope_done); \
550+
(UNUSED(MisraScope), UNPL(scope_done)); \
551551
UNPL(scope_done) = NULL)
552552

553553
///
@@ -568,7 +568,8 @@ extern "C" {
568568
/// TAGS: Allocator, Scope, Lifetime
569569
///
570570
#define ScopeWith(alloc_ptr) \
571-
for (Allocator *MisraScope = (alloc_ptr), *UNPL(scope_with_done) = MisraScope; UNPL(scope_with_done); \
571+
for (Allocator *MisraScope = (alloc_ptr), *UNPL(scope_with_done) = MisraScope; \
572+
(UNUSED(MisraScope), UNPL(scope_with_done)); \
572573
UNPL(scope_with_done) = NULL)
573574

574575
///

Include/Misra/Std/Allocator/Budget.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,15 @@ extern "C" {
142142
ALIGN_UP_POW2((slot_size_bytes), (alignment_value)) + ((alignment_value) - 1), \
143143
"BudgetAllocatorInit: buffer too small for bitmap + one padded slot" \
144144
), \
145-
(MemSet( \
146-
PTR_ALIGN_UP_POW2((buf_ptr), 8u), \
147-
0, \
148-
CEIL_DIV( \
149-
((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) / \
150-
ALIGN_UP_POW2((slot_size_bytes), (alignment_value)), \
151-
64u \
152-
) * sizeof(u64) \
153-
), \
154-
0), \
145+
MemSet( \
146+
PTR_ALIGN_UP_POW2((buf_ptr), 8u), \
147+
0, \
148+
CEIL_DIV( \
149+
((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) / \
150+
ALIGN_UP_POW2((slot_size_bytes), (alignment_value)), \
151+
64u \
152+
) * sizeof(u64) \
153+
), \
155154
((BudgetAllocator) { \
156155
.base = \
157156
{.allocate = budget_allocator_allocate, \

Include/Misra/Types.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,25 @@ typedef i8 bool;
204204
# define FORCE_INLINE inline
205205
#endif
206206

207+
///
208+
/// Mark `x` as deliberately unused at this point. Expands to the
209+
/// canonical `(void)(x)` cast -- works on every C compiler (no
210+
/// `__attribute__` / `__pragma` dispatch needed). Use it to silence
211+
/// `-Wunused-variable` / `-Wunused-parameter` on a name that the
212+
/// surrounding code legitimately doesn't touch, and to mark a
213+
/// scope-default like `MisraScope` as "read" when the body never
214+
/// references it.
215+
///
216+
/// USAGE:
217+
/// void cb(int reason, void *ctx) {
218+
/// UNUSED(reason);
219+
/// UNUSED(ctx);
220+
/// ...
221+
/// }
222+
///
223+
/// TAGS: Codegen, Compiler-Portability, Utility
224+
#define UNUSED(x) ((void)(x))
225+
207226
///
208227
/// Count trailing zero bits in a 64-bit word. Undefined for `x == 0`
209228
/// (matches the underlying compiler builtin's contract); callers must

Source/Misra/Std/Container/Map.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const MapPolicy MapPolicyQuadratic = {
179179
.max_probe_count = 128,
180180
};
181181

182-
static inline char *map_entry_ptr(const GenericMap *map, size entry_size, size idx) {
182+
static inline u8 *map_entry_ptr(const GenericMap *map, size entry_size, size idx) {
183183
return map->entries + (idx * entry_size);
184184
}
185185

@@ -217,7 +217,7 @@ static void map_deinit_slot(GenericMap *map, size entry_size, size key_offset, s
217217

218218
static bool map_copy_into_entry(
219219
GenericMap *map,
220-
char *entry,
220+
u8 *entry,
221221
size entry_size,
222222
size key_offset,
223223
size key_size,
@@ -493,10 +493,10 @@ bool rehash_map(
493493
size n,
494494
MapPolicy policy
495495
) {
496-
char *old_entries;
497-
u8 *old_states;
498-
char *new_entries;
499-
u8 *new_states;
496+
u8 *old_entries;
497+
u8 *old_states;
498+
u8 *new_entries;
499+
u8 *new_states;
500500
size old_capacity;
501501
size new_capacity;
502502
size idx;
@@ -1036,7 +1036,7 @@ bool map_set_only(
10361036
size value_size,
10371037
size hash_offset
10381038
) {
1039-
char *temp_entry;
1039+
u8 *temp_entry;
10401040
size existing_idx;
10411041
u64 hash;
10421042

Source/Misra/Sys/Proc.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,21 @@ static inline long misra_proc_waitpid(int pid, int *status, int options) {
123123
// Macro shims so the existing POSIX call sites use our direct-syscall
124124
// wrappers without per-line edits. Each returns the kernel's value
125125
// (negative = -errno, otherwise success), and the callers already
126-
// handle the "< 0" failure shape that POSIX wrappers expose.
127-
# define close(fd) ((int)misra_proc_close(fd))
128-
# define read(fd, buf, n) ((long)misra_proc_read((fd), (buf), (n)))
129-
# define write(fd, buf, n) ((long)misra_proc_write((fd), (buf), (n)))
130-
# define pipe(fds) ((int)misra_proc_pipe(fds))
131-
# define dup2(oldfd, newfd) ((int)misra_proc_dup2((oldfd), (newfd)))
132-
# define fork() ((pid_t)misra_proc_fork())
133-
# define execve(p, a, e) ((int)misra_proc_execve((p), (a), (e)))
134-
# define kill(pid, sig) ((int)misra_proc_kill((pid), (sig)))
135-
# define readlink(p, b, n) ((long)misra_proc_readlink((p), (b), (n)))
136-
# define waitpid(pid, status, opts) ((pid_t)misra_proc_waitpid((pid), (status), (opts)))
126+
// handle the "< 0" failure shape that POSIX wrappers expose. No outer
127+
// cast: callers that bind the result get the implicit conversion
128+
// (long -> int / pid_t / etc.), and callers that discard the result
129+
// don't get `-Wunused-value` from a cast in expression-statement
130+
// position.
131+
# define close(fd) misra_proc_close(fd)
132+
# define read(fd, buf, n) misra_proc_read((fd), (buf), (n))
133+
# define write(fd, buf, n) misra_proc_write((fd), (buf), (n))
134+
# define pipe(fds) misra_proc_pipe(fds)
135+
# define dup2(oldfd, newfd) misra_proc_dup2((oldfd), (newfd))
136+
# define fork() misra_proc_fork()
137+
# define execve(p, a, e) misra_proc_execve((p), (a), (e))
138+
# define kill(pid, sig) misra_proc_kill((pid), (sig))
139+
# define readlink(p, b, n) misra_proc_readlink((p), (b), (n))
140+
# define waitpid(pid, status, opts) misra_proc_waitpid((pid), (status), (opts))
137141
#endif
138142

139143
#ifndef STDIN_FILENO

0 commit comments

Comments
 (0)