Skip to content

Commit 473f7e6

Browse files
osamu620claude
andcommitted
fix(coding): widen uint32_t multiplications to size_t before memset
Cast the first operand to size_t in 12 memset size expressions where uint32_t × uint32_t was implicitly widened after the multiplication. Resolves all 12 CodeQL cpp/integer-multiplication-cast-to-long alerts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9115148 commit 473f7e6

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

source/core/coding/coding_units.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5789,15 +5789,15 @@ void j2k_tile::decode_line_based_predecoded(j2k_main_header &hdr, uint8_t reduce
57895789
const bool is_ht = (block->Cmodes & HT) >> 6;
57905790
if (!is_ht) {
57915791
// EBCOT: all three buffers must be pre-zeroed.
5792-
memset(block->sample_buf, 0, QWx2 * QHx2 * sizeof(int32_t));
5793-
memset(block->block_states, 0, (QWx2 + 2) * (QHx2 + 2));
5792+
memset(block->sample_buf, 0, static_cast<size_t>(QWx2) * QHx2 * sizeof(int32_t));
5793+
memset(block->block_states, 0, static_cast<size_t>(QWx2 + 2) * (QHx2 + 2));
57945794
memset(block->block_contexts, 0,
5795-
(QHx2 / 4 + 2) * (QWx2 + 2) * sizeof(uint32_t));
5795+
static_cast<size_t>(QHx2 / 4 + 2) * (QWx2 + 2) * sizeof(uint32_t));
57965796
} else if (block->num_passes > 1) {
57975797
// HT multi-pass: sigprop/magref read the block_states border
57985798
// (written by cleanup only for the interior). Zero block_states;
57995799
// sample_buf is fully written by cleanup before sigprop reads it.
5800-
memset(block->block_states, 0, (QWx2 + 2) * (QHx2 + 2));
5800+
memset(block->block_states, 0, static_cast<size_t>(QWx2 + 2) * (QHx2 + 2));
58015801
}
58025802
// HT single-pass: ht_cleanup_decode initialises all positions
58035803
// before reading — no pre-zeroing needed.

source/core/coding/subband_row_buf.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ void j2k_subband_row_buf::decode_strip_core(sprec_t *target_buf, int32_t y0, int
310310
bt.block->i_samples = target_buf + bt.row_off + bt.col_off;
311311
const bool is_ht = (bt.block->Cmodes & HT) >> 6;
312312
if (!is_ht) {
313-
std::memset(bt.block->sample_buf, 0, bt.QWx2 * bt.QHx2 * sizeof(int32_t));
314-
std::memset(bt.block->block_states, 0, (bt.QWx2 + 2) * (bt.QHx2 + 2));
313+
std::memset(bt.block->sample_buf, 0, static_cast<size_t>(bt.QWx2) * bt.QHx2 * sizeof(int32_t));
314+
std::memset(bt.block->block_states, 0, static_cast<size_t>(bt.QWx2 + 2) * (bt.QHx2 + 2));
315315
std::memset(bt.block->block_contexts, 0,
316-
(bt.QHx2 / 4 + 2) * (bt.QWx2 + 2) * sizeof(uint32_t));
316+
static_cast<size_t>(bt.QHx2 / 4 + 2) * (bt.QWx2 + 2) * sizeof(uint32_t));
317317
} else if (bt.block->num_passes > 1) {
318-
std::memset(bt.block->block_states, 0, (bt.QWx2 + 2) * (bt.QHx2 + 2));
318+
std::memset(bt.block->block_states, 0, static_cast<size_t>(bt.QWx2 + 2) * (bt.QHx2 + 2));
319319
}
320320
}
321321
// Batch-push all tasks under a single mutex lock + notify_all.
@@ -655,12 +655,12 @@ void j2k_subband_row_buf::trigger_prefetch(int32_t next_y0) {
655655
pb.block->i_samples = pbuf + pb.row_off + pb.col_off;
656656
const bool is_ht = (pb.block->Cmodes & HT) >> 6;
657657
if (!is_ht) {
658-
std::memset(pb.block->sample_buf, 0, pb.QWx2 * pb.QHx2 * sizeof(int32_t));
659-
std::memset(pb.block->block_states, 0, (pb.QWx2 + 2) * (pb.QHx2 + 2));
658+
std::memset(pb.block->sample_buf, 0, static_cast<size_t>(pb.QWx2) * pb.QHx2 * sizeof(int32_t));
659+
std::memset(pb.block->block_states, 0, static_cast<size_t>(pb.QWx2 + 2) * (pb.QHx2 + 2));
660660
std::memset(pb.block->block_contexts, 0,
661-
(pb.QHx2 / 4 + 2) * (pb.QWx2 + 2) * sizeof(uint32_t));
661+
static_cast<size_t>(pb.QHx2 / 4 + 2) * (pb.QWx2 + 2) * sizeof(uint32_t));
662662
} else if (pb.block->num_passes > 1) {
663-
std::memset(pb.block->block_states, 0, (pb.QWx2 + 2) * (pb.QHx2 + 2));
663+
std::memset(pb.block->block_states, 0, static_cast<size_t>(pb.QWx2 + 2) * (pb.QHx2 + 2));
664664
}
665665
}
666666
// Batch-push all tasks under a single mutex lock + notify_all.

0 commit comments

Comments
 (0)