Skip to content

Commit 67e10fc

Browse files
committed
[ CID 15998 ] engine: combiners.cpp: Uninitialized scaler variable in advanced_imaging_combiner
Fixed by splitting different operation types into separate enums and using templates with enum types to avoid casts from int
1 parent 6ce60b4 commit 67e10fc

1 file changed

Lines changed: 62 additions & 21 deletions

File tree

engine/src/combiners.cpp

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef unsigned char uint8_t;
2525

2626
static uint32_t g_current_background_colour = 0;
2727

28-
enum Operation
28+
enum BitwiseOperation
2929
{
3030
// Bitwise
3131
OPERATION_CLEAR, // 0
@@ -44,19 +44,25 @@ enum Operation
4444
OPERATION_OR_INVERTED,
4545
OPERATION_NAND,
4646
OPERATION_SET,
47+
};
4748

49+
enum ArithmeticOperation
50+
{
4851
// Arithmetic
49-
OPERATION_BLEND, // 16
52+
OPERATION_BLEND = OPERATION_SET + 1, // 16
5053
OPERATION_ADD_PIN,
5154
OPERATION_ADD_OVER,
5255
OPERATION_SUB_PIN,
5356
OPERATION_TRANSPARENT,
5457
OPERATION_AD_MAX,
5558
OPERATION_SUB_OVER,
5659
OPERATION_AD_MIN,
60+
};
5761

62+
enum BasicImagingOperation
63+
{
5864
// Basic Imaging Blends
59-
OPERATION_BLEND_CLEAR, // 24
65+
OPERATION_BLEND_CLEAR = OPERATION_AD_MIN + 1, // 24
6066
OPERATION_BLEND_SRC,
6167
OPERATION_BLEND_DST,
6268
OPERATION_BLEND_SRC_OVER,
@@ -71,9 +77,12 @@ enum Operation
7177
OPERATION_BLEND_PLUS, //36
7278
OPERATION_BLEND_MULTIPLY,
7379
OPERATION_BLEND_SCREEN,
80+
};
7481

82+
enum AdvancedImagingOperation
83+
{
7584
// Advanced Imaging Blends
76-
OPERATION_BLEND_OVERLAY,
85+
OPERATION_BLEND_OVERLAY = OPERATION_BLEND_SCREEN + 1,
7786
OPERATION_BLEND_DARKEN,
7887
OPERATION_BLEND_LIGHTEN,
7988
OPERATION_BLEND_DODGE,
@@ -82,11 +91,11 @@ enum Operation
8291
OPERATION_BLEND_SOFT_LIGHT,
8392
OPERATION_BLEND_DIFFERENCE,
8493
OPERATION_BLEND_EXCLUSION,
85-
86-
OPERATION_SRC_BIC = OPERATION_AND_REVERSE,
87-
OPERATION_NOT_SRC_BIC = OPERATION_AND,
8894
};
8995

96+
#define OPERATION_SRC_BIC OPERATION_AND_REVERSE
97+
#define OPERATION_NOT_SRC_BIC OPERATION_AND
98+
9099
typedef void (*surface_combiner_t)(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity);
91100

92101
#ifdef __VISUALC__
@@ -320,7 +329,7 @@ template<typename Type> INLINE Type fastmax(Type a, Type b)
320329
return a < b ? b : a;
321330
}
322331

323-
template<Operation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t bitwise_combiner(uint32_t dst, uint32_t src)
332+
template<BitwiseOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t bitwise_combiner(uint32_t dst, uint32_t src)
324333
{
325334
uint8_t sa, da;
326335
uint32_t r, s, d;
@@ -418,7 +427,7 @@ template<Operation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32
418427
}
419428

420429
extern uint32_t g_current_background_colour;
421-
template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t arithmetic_combiner(uint32_t dst, uint32_t src)
430+
template<ArithmeticOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t arithmetic_combiner(uint32_t dst, uint32_t src)
422431
{
423432
uint8_t sa, da;
424433
uint32_t s, d;
@@ -547,7 +556,7 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t ari
547556
return r;
548557
}
549558

550-
template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t basic_imaging_combiner(uint32_t dst, uint32_t src)
559+
template<BasicImagingOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t basic_imaging_combiner(uint32_t dst, uint32_t src)
551560
{
552561
uint32_t r;
553562
switch(x_combiner)
@@ -648,7 +657,7 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t bas
648657
return r;
649658
}
650659

651-
template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t advanced_imaging_combiner(uint32_t dst, uint32_t src)
660+
template<AdvancedImagingOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t advanced_imaging_combiner(uint32_t dst, uint32_t src)
652661
{
653662
uint8_t t_src_red, t_src_green, t_src_blue, t_src_alpha;
654663
uint8_t t_dst_red, t_dst_green, t_dst_blue, t_dst_alpha;
@@ -875,19 +884,28 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t adv
875884
return t_red | (t_green << 8) | (t_blue << 16);
876885
}
877886

878-
template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t pixel_combine(uint32_t dst, uint32_t src)
887+
template<BitwiseOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t pixel_combine(uint32_t dst, uint32_t src)
879888
{
880-
if (x_combiner <= OPERATION_SET)
881-
return bitwise_combiner<(Operation)x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
882-
else if (x_combiner <= OPERATION_AD_MIN)
883-
return arithmetic_combiner<(Operation)x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
884-
else if (x_combiner <= OPERATION_BLEND_SCREEN)
885-
return basic_imaging_combiner<(Operation)x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
886-
else
887-
return advanced_imaging_combiner<x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
889+
return bitwise_combiner<x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
890+
}
891+
892+
template<ArithmeticOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t pixel_combine(uint32_t dst, uint32_t src)
893+
{
894+
return arithmetic_combiner<x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
895+
}
896+
897+
template<BasicImagingOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t pixel_combine(uint32_t dst, uint32_t src)
898+
{
899+
return basic_imaging_combiner<x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
888900
}
889901

890-
template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> void surface_combine(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity)
902+
template<AdvancedImagingOperation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t pixel_combine(uint32_t dst, uint32_t src)
903+
{
904+
return advanced_imaging_combiner<x_combiner, x_dst_alpha, x_src_alpha>(dst, src);
905+
}
906+
907+
template<class T, T x_combiner, bool x_dst_alpha, bool x_src_alpha>
908+
INLINE void surface_combine(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity)
891909
{
892910
if (p_opacity == 0)
893911
return;
@@ -923,6 +941,29 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> void surface_combin
923941
}
924942
}
925943

944+
template <BitwiseOperation x_combiner, bool x_dst_alpha, bool x_src_alpha>
945+
void surface_combine(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity)
946+
{
947+
return surface_combine<BitwiseOperation, x_combiner, x_dst_alpha, x_src_alpha>(p_dst, p_dst_stride, p_src, p_src_stride, p_width, p_height, p_opacity);
948+
}
949+
950+
template <ArithmeticOperation x_combiner, bool x_dst_alpha, bool x_src_alpha>
951+
void surface_combine(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity)
952+
{
953+
return surface_combine<ArithmeticOperation, x_combiner, x_dst_alpha, x_src_alpha>(p_dst, p_dst_stride, p_src, p_src_stride, p_width, p_height, p_opacity);
954+
}
955+
956+
template <BasicImagingOperation x_combiner, bool x_dst_alpha, bool x_src_alpha>
957+
void surface_combine(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity)
958+
{
959+
return surface_combine<BasicImagingOperation, x_combiner, x_dst_alpha, x_src_alpha>(p_dst, p_dst_stride, p_src, p_src_stride, p_width, p_height, p_opacity);
960+
}
961+
962+
template <AdvancedImagingOperation x_combiner, bool x_dst_alpha, bool x_src_alpha>
963+
void surface_combine(void *p_dst, int32_t p_dst_stride, const void *p_src, uint32_t p_src_stride, uint32_t p_width, uint32_t p_height, uint8_t p_opacity)
964+
{
965+
return surface_combine<AdvancedImagingOperation, x_combiner, x_dst_alpha, x_src_alpha>(p_dst, p_dst_stride, p_src, p_src_stride, p_width, p_height, p_opacity);
966+
}
926967

927968
// MW-2009-02-09: This is the most important combiner so we optimize it.
928969
// This optimization is based on the observation that:

0 commit comments

Comments
 (0)