Skip to content

Commit

Permalink
Workaround 'checking if unsigned ofs_sz_ull < 0' cppcheck FP in mark_…
Browse files Browse the repository at this point in the history
…rts.c

(fix of commit 93f4212)

* include/private/gc_priv.h [E2K] (PS_COMPUTE_ADJUSTED_OFS): Define
macro (different implementations for multi- and single-threaded builds,
move part of code from GET_PROCEDURE_STACK_LOCAL).
* include/private/gc_priv.h [E2K] (GET_PROCEDURE_STACK_LOCAL): Use
PS_COMPUTE_ADJUSTED_OFS().
  • Loading branch information
ivmai committed Dec 3, 2023
1 parent cc5edd9 commit 027a48e
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,27 @@ GC_INNER void GC_with_callee_saves_pushed(void (*volatile fn)(ptr_t, void *),
GC_ASSERT(*(psz_ull) > 0 && *(psz_ull) % sizeof(word) == 0); \
} while (0)

# ifdef THREADS
# define PS_COMPUTE_ADJUSTED_OFS(padj_ps_ofs, ps_ofs, ofs_sz_ull) \
do { \
if ((ofs_sz_ull) <= (ps_ofs) /* && ofs_sz_ull > 0 */) \
ABORT_ARG2("Incorrect size of procedure stack", \
": ofs= %lu, size= %lu", \
(unsigned long)(ps_ofs), \
(unsigned long)(ofs_sz_ull)); \
*(padj_ps_ofs) = (ps_ofs) > PS_SYSCALL_TAIL_BYTES ? \
(ps_ofs) - PS_SYSCALL_TAIL_BYTES : 0; \
} while (0)
# else
/* A simplified version of the above assuming ps_ofs is a zero const. */
# define PS_COMPUTE_ADJUSTED_OFS(padj_ps_ofs, ps_ofs, ofs_sz_ull) \
do { \
GC_STATIC_ASSERT((ps_ofs) == 0); \
(void)(ofs_sz_ull); \
*(padj_ps_ofs) = 0; \
} while (0)
# endif /* !THREADS */

/* Copy procedure (register) stack to a stack-allocated buffer. */
/* Usable from a signal handler. The buffer is valid only within */
/* the current function. ps_ofs designates the offset in the */
Expand All @@ -2058,12 +2079,7 @@ GC_INNER void GC_with_callee_saves_pushed(void (*volatile fn)(ptr_t, void *),
size_t adj_ps_ofs; \
\
GET_PROCEDURE_STACK_SIZE_INNER(&ofs_sz_ull); \
if (ofs_sz_ull <= (ps_ofs)) \
ABORT_ARG2("Incorrect size of procedure stack", \
": ofs= %lu, size= %lu", (unsigned long)(ps_ofs), \
(unsigned long)ofs_sz_ull); \
adj_ps_ofs = (ps_ofs) > PS_SYSCALL_TAIL_BYTES ? \
(ps_ofs) - PS_SYSCALL_TAIL_BYTES : 0; \
PS_COMPUTE_ADJUSTED_OFS(&adj_ps_ofs, ps_ofs, ofs_sz_ull); \
*(psz) = (size_t)ofs_sz_ull - adj_ps_ofs; \
/* Allocate buffer on the stack; cannot return NULL. */ \
*(pbuf) = PS_ALLOCA_BUF(*(psz)); \
Expand Down

0 comments on commit 027a48e

Please sign in to comment.