Skip to content

Commit

Permalink
This address codeQL
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Nov 10, 2024
1 parent 576fef9 commit 6541f2c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -64,7 +64,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -77,6 +77,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
26 changes: 13 additions & 13 deletions src/apps/others/ojph_img_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ namespace ojph {
return;

if (bytes_per_sample == 1)
temp_buf = alloc_p->post_alloc_data<ui8>(num_comps * width, 0);
temp_buf = alloc_p->post_alloc_data<ui8>(num_comps * (size_t)width, 0);
else
temp_buf = alloc_p->post_alloc_data<ui16>(num_comps * width, 0);
temp_buf = alloc_p->post_alloc_data<ui16>(num_comps * (size_t)width, 0);
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -408,7 +408,7 @@ namespace ojph {
"unable to open file %s for writing", filename);

fprintf(fh, "P5\n%d %d\n%d\n", width, height, (1 << bit_depth) - 1);
buffer_size = width * bytes_per_sample;
buffer_size = (size_t)width * bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
}
else
Expand All @@ -435,7 +435,7 @@ namespace ojph {
fprintf(fh, "P6\n%d %d\n%d\n", width, height, (1 << bit_depth) - 1);
if (result == 0)
OJPH_ERROR(0x03000027, "error writing to file %s", filename);
buffer_size = width * num_components * bytes_per_sample;
buffer_size = (size_t)width * num_components * (size_t)bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
}
fname = filename;
Expand Down Expand Up @@ -935,12 +935,12 @@ namespace ojph {
// the first time trying to access this line
if (PLANARCONFIG_SEPARATE == planar_configuration && 0 == comp_num )
{
for (unsigned short color = 0; color < num_comps; color++)
for (ui32 color = 0; color < num_comps; color++)
{
if (bytes_per_sample == 1)
{
TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint8,
cur_line, color);
cur_line, (ui16)color);
ui32 x = color;
uint8_t* line_buffer_of_interleaved_components =
(uint8_t*)line_buffer;
Expand All @@ -953,7 +953,7 @@ namespace ojph {
else if (bytes_per_sample == 2)
{
TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint16,
cur_line, color);
cur_line, (ui16)color);
ui32 x = color;
ui16* line_buffer_of_interleaved_components = (ui16*)line_buffer;
for (ui32 i = 0; i < width; i++, x += num_comps)
Expand Down Expand Up @@ -1070,7 +1070,7 @@ namespace ojph {
OJPH_ERROR(0x030000B3, "unable to open file %s for writing", filename);
}

buffer_size = width * num_components * bytes_per_sample;
buffer_size = (size_t)width * num_components * (size_t)bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
fname = filename;
cur_line = 0;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ namespace ojph {
bytes_per_sample = 2;
}
samples_per_line = num_components * width;
bytes_per_line = bytes_per_sample * samples_per_line;
bytes_per_line = bytes_per_sample * (size_t)samples_per_line;

}

Expand Down Expand Up @@ -1482,7 +1482,7 @@ namespace ojph {

cur_line = 0;
bytes_per_sample = (bit_depth + 7) >> 3;
buffer_size = width * bytes_per_sample;
buffer_size = (size_t)width * bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
fname = filename;
}
Expand Down Expand Up @@ -1626,7 +1626,7 @@ namespace ojph {
}

bytes_per_sample = (bit_depth + 7) >> 3;
buffer_size = width * bytes_per_sample;
buffer_size = (size_t)width * bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
}

Expand Down Expand Up @@ -2004,11 +2004,11 @@ namespace ojph {

// allocate line_buffer_16bit_samples to hold a line of image data in memory
line_buffer_16bit_samples =
(ui16*) malloc(width * num_comps * sizeof(ui16));
(ui16*) malloc((size_t)width * num_comps * sizeof(ui16));
if (NULL == line_buffer_16bit_samples)
OJPH_ERROR(0x03000179, "Unable to allocate %d bytes for "
"line_buffer_16bit_samples[] for file %s",
width * num_comps * sizeof(ui16), filename);
(size_t)width * num_comps * sizeof(ui16), filename);

cur_line = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/core/codestream/ojph_codeblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ namespace ojph {
const param_cod* cd = codestream->get_cod(comp_num);
ui32 precision = cd->propose_implementation_precision(sz);
if (precision <= 32)
allocator->pre_alloc_data<ui32>(nominal.h * stride, 0);
allocator->pre_alloc_data<ui32>(nominal.h * (size_t)stride, 0);
else
allocator->pre_alloc_data<ui64>(nominal.h * stride, 0);
allocator->pre_alloc_data<ui64>(nominal.h * (size_t)stride, 0);
}

//////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 9 additions & 5 deletions src/core/codestream/ojph_resolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ namespace ojph {
bands[1].pull_line(), width, horz_even);
else
memcpy(aug->line->p, child_res->pull_line()->p,
width * (aug->line->flags & line_buf::LFT_SIZE_MASK));
(size_t)width
* (aug->line->flags & line_buf::LFT_SIZE_MASK));
aug->active = true;
vert_even = !vert_even;
++cur_line;
Expand All @@ -721,7 +722,8 @@ namespace ojph {
bands[3].pull_line(), width, horz_even);
else
memcpy(sig->line->p, bands[2].pull_line()->p,
width * (sig->line->flags & line_buf::LFT_SIZE_MASK));
(size_t)width
* (sig->line->flags & line_buf::LFT_SIZE_MASK));
sig->active = true;
vert_even = !vert_even;
++cur_line;
Expand Down Expand Up @@ -760,7 +762,8 @@ namespace ojph {
bands[1].pull_line(), width, horz_even);
else
memcpy(aug->line->p, child_res->pull_line()->p,
width * (aug->line->flags & line_buf::LFT_SIZE_MASK));
(size_t)width
* (aug->line->flags & line_buf::LFT_SIZE_MASK));
}
else
{
Expand All @@ -769,7 +772,8 @@ namespace ojph {
bands[3].pull_line(), width, horz_even);
else
memcpy(aug->line->p, bands[2].pull_line()->p,
width * (aug->line->flags & line_buf::LFT_SIZE_MASK));
(size_t)width
* (aug->line->flags & line_buf::LFT_SIZE_MASK));
if (aug->line->flags & line_buf::LFT_32BIT)
{
si32* sp = aug->line->i32;
Expand Down Expand Up @@ -891,7 +895,7 @@ namespace ojph {
bands[1].pull_line(), width, horz_even);
else
memcpy(aug->line->p, child_res->pull_line()->p,
width * (aug->line->flags & line_buf::LFT_SIZE_MASK));
(size_t)width * (aug->line->flags & line_buf::LFT_SIZE_MASK));
return aug->line;
}
else
Expand Down

0 comments on commit 6541f2c

Please sign in to comment.