Skip to content

Commit 57dc9a0

Browse files
committed
Make CodeQL happy
1 parent 1acde49 commit 57dc9a0

6 files changed

Lines changed: 16 additions & 17 deletions

File tree

src/calibre/gui2/pictureflow/pictureflow.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ void PictureFlowPrivate::resetSlides()
587587
{
588588
SlideInfo& si = leftSlides[i];
589589
si.angle = itilt;
590-
si.cx = -(offsetX + spacing*i*PFREAL_ONE);
590+
si.cx = -(offsetX + (long)spacing*i*PFREAL_ONE);
591591
si.cy = offsetY;
592592
si.slideIndex = centerIndex-1-i;
593593
//qDebug() << "Left[" << i << "] x=" << fixedToFloat(si.cx) << ", y=" << fixedToFloat(si.cy) ;
@@ -599,7 +599,7 @@ void PictureFlowPrivate::resetSlides()
599599
{
600600
SlideInfo& si = rightSlides[i];
601601
si.angle = -itilt;
602-
si.cx = offsetX + spacing*i*PFREAL_ONE;
602+
si.cx = offsetX + (long)spacing*i*PFREAL_ONE;
603603
si.cy = offsetY;
604604
si.slideIndex = centerIndex+1+i;
605605
//qDebug() << "Right[" << i << "] x=" << fixedToFloat(si.cx) << ", y=" << fixedToFloat(si.cy) ;
@@ -1118,7 +1118,7 @@ void PictureFlowPrivate::updateAnimation()
11181118
speed = 512 + 16384 * (PFREAL_ONE+fsin(ia))/PFREAL_ONE;
11191119
}
11201120

1121-
slideFrame += speed*step;
1121+
slideFrame += (long long)speed*step;
11221122

11231123
int index = slideFrame >> 16;
11241124
int pos = slideFrame & 0xffff;
@@ -1161,15 +1161,15 @@ void PictureFlowPrivate::updateAnimation()
11611161
{
11621162
SlideInfo& si = leftSlides[i];
11631163
si.angle = itilt;
1164-
si.cx = -(offsetX + spacing*i*PFREAL_ONE + step*spacing*ftick);
1164+
si.cx = -(offsetX + (long)spacing*i*PFREAL_ONE + (long)step*spacing*ftick);
11651165
si.cy = offsetY;
11661166
}
11671167

11681168
for(int i = 0; i < rightSlides.count(); i++)
11691169
{
11701170
SlideInfo& si = rightSlides[i];
11711171
si.angle = -itilt;
1172-
si.cx = offsetX + spacing*i*PFREAL_ONE - step*spacing*ftick;
1172+
si.cx = offsetX + (long)spacing*i*PFREAL_ONE - (long)step*spacing*ftick;
11731173
si.cy = offsetY;
11741174
}
11751175

src/calibre/utils/ffmpeg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ resample_raw_audio_16bit(PyObject *self, PyObject *args) {
510510
);
511511
Py_END_ALLOW_THREADS
512512
if (ret < 0) { free_resources; return averror_as_python_with_gil_held(ret, __LINE__); }
513-
output_size = ret * output_num_channels * bytes_per_sample;
513+
output_size = (int64_t)ret * (int64_t)output_num_channels * bytes_per_sample;
514514
PyObject *ans = PyBytes_FromStringAndSize((char*)output, output_size);
515515
free_resources;
516516
#undef free_resources

src/calibre/utils/imageops/imageops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static QImage convolve(const QImage &image, int matrix_size, float *matrix) {
174174
if (buffer.isNull()) throw std::bad_alloc();
175175
buf1.resize(matrix_size);
176176
scanblock = buf1.data();
177-
buf2.resize(matrix_size * matrix_size);
177+
buf2.resize((qsizetype)matrix_size * matrix_size);
178178
normalize_matrix = buf2.data();
179179

180180
// create normalized matrix

src/calibre/utils/lzx/lzxc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define LZ_ONEBUFFER 1
1919
#define LAZY 1
2020

21-
#include <stdio.h>
2221
#include <stdlib.h>
2322
#include <stdint.h>
2423
#include <string.h> /* for memset on Linux */
@@ -1143,7 +1142,7 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
11431142
build_huffman_tree(LZX_ALIGNED_SIZE, 7, lzxd->aligned_freq_table, lzxd->aligned_tree);
11441143
for (i = 0; i < LZX_ALIGNED_SIZE; i++) {
11451144
uncomp_bits += lzxd->aligned_freq_table[i]* 3;
1146-
comp_bits += lzxd->aligned_freq_table[i]* lzxd->aligned_tree[i].codelength;
1145+
comp_bits += (long)lzxd->aligned_freq_table[i]* lzxd->aligned_tree[i].codelength;
11471146
}
11481147
comp_bits_ovh = comp_bits + LZX_ALIGNED_SIZE * 3;
11491148
if (comp_bits_ovh < uncomp_bits)

src/calibre/utils/lzx/lzxd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
224224
unsigned int next_symbol = bit_mask; /* base of allocation for long codes */
225225

226226
/* fill entries for codes short enough for a direct mapping */
227-
for (bit_num = 1; bit_num <= nbits; bit_num++) {
228-
for (sym = 0; sym < nsyms; sym++) {
227+
for (bit_num = 1; (unsigned)bit_num <= nbits; bit_num++) {
228+
for (sym = 0; (unsigned)sym < nsyms; sym++) {
229229
if (length[sym] != bit_num) continue;
230230
leaf = pos;
231231
if((pos += bit_mask) > table_mask) return 1; /* table overrun */
@@ -239,15 +239,15 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
239239
if (pos == table_mask) return 0;
240240

241241
/* clear the remainder of the table */
242-
for (sym = pos; sym < table_mask; sym++) table[sym] = 0xFFFF;
242+
for (sym = pos; (unsigned)sym < table_mask; sym++) table[sym] = 0xFFFF;
243243

244244
/* allow codes to be up to nbits+16 long, instead of nbits */
245245
pos <<= 16;
246246
table_mask <<= 16;
247247
bit_mask = 1 << 15;
248248

249249
for (bit_num = nbits+1; bit_num <= 16; bit_num++) {
250-
for (sym = 0; sym < nsyms; sym++) {
250+
for (sym = 0; (unsigned)sym < nsyms; sym++) {
251251
if (length[sym] != bit_num) continue;
252252

253253
leaf = pos >> 16;
@@ -273,7 +273,7 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
273273
if (pos == table_mask) return 0;
274274

275275
/* either erroneous table, or all elements are 0 - let's find out. */
276-
for (sym = 0; sym < nsyms; sym++) if (length[sym]) return 1;
276+
for (sym = 0; (unsigned)sym < nsyms; sym++) if (length[sym]) return 1;
277277
return 0;
278278
}
279279

src/calibre/utils/matcher.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct {
2727

2828
static MemoryItem*** alloc_memory(int32_t needle_len, int32_t max_haystack_len) {
2929
MemoryItem ***ans = NULL, **d1 = NULL, *d2 = NULL;
30-
size_t num = max_haystack_len * max_haystack_len * needle_len;
30+
size_t num = (size_t)max_haystack_len * (size_t)max_haystack_len * needle_len;
3131
size_t position_sz = needle_len * sizeof(int32_t);
3232
size_t sz = (num * (sizeof(MemoryItem) + position_sz)) + (max_haystack_len * sizeof(MemoryItem**)) + (needle_len * sizeof(MemoryItem*));
3333
int32_t hidx, nidx, last_idx, i, j;
@@ -85,7 +85,7 @@ typedef struct {
8585
static void alloc_stack(Stack *stack, int32_t needle_len, int32_t max_haystack_len) {
8686
StackItem *ans = NULL;
8787
char *base = NULL;
88-
size_t num = max_haystack_len * needle_len;
88+
size_t num = (size_t)max_haystack_len * needle_len;
8989
size_t position_sz = needle_len * sizeof(int32_t);
9090
size_t sz = sizeof(StackItem) + position_sz;
9191
size_t i = 0;
@@ -416,7 +416,7 @@ Matcher_calculate_scores(Matcher *self, PyObject *args) {
416416
items = PyTuple_New(self->item_count);
417417
positions = PyTuple_New(self->item_count);
418418
matches = (Match*)calloc(self->item_count, sizeof(Match));
419-
final_positions = (int32_t*) calloc(needle_char_len * self->item_count, sizeof(int32_t));
419+
final_positions = (int32_t*) calloc((size_t)needle_char_len * self->item_count, sizeof(int32_t));
420420
if (items == NULL || matches == NULL || final_positions == NULL || positions == NULL) {PyErr_NoMemory(); goto end;}
421421

422422
for (i = 0; i < self->item_count; i++) {

0 commit comments

Comments
 (0)