Skip to content

Commit 2819460

Browse files
authored
Merge pull request #291 from Libvisual/fix-gforce-gcc-warnings.
Plugins (gforce): Fix GCC warnings.
2 parents 53b86b6 + c11eaca commit 2819460

File tree

9 files changed

+69
-26
lines changed

9 files changed

+69
-26
lines changed

libvisual-plugins/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
7676
CHECK_FUNCTION_EXISTS(mremap HAVE_MREMAP)
7777
#AC_FUNC_MMAP
7878

79+
INCLUDE(CheckTypeSize)
80+
7981
# Assembly
8082
#AM_PROG_AS
8183

@@ -215,6 +217,14 @@ IF(ENABLE_GOOM2K4)
215217
ENDIF()
216218
ENDIF()
217219

220+
IF(ENABLE_GFORCE)
221+
CHECK_TYPE_SIZE(float CXX_FLOAT_SIZE LANGUAGE CXX)
222+
IF(NOT CXX_FLOAT_SIZE EQUAL 4)
223+
MESSAGE(WARNING "G-Force requires 32-bit floats.")
224+
SET(ENABLE_GFORCE no)
225+
ENDIF()
226+
ENDIF()
227+
218228
IF(ENABLE_GSTREAMER)
219229
PKG_CHECK_MODULES(GSTREAMER gstreamer-1.0>=${GST_REQUIRED_VERSION} IMPORTED_TARGET)
220230
IF(NOT GSTREAMER_FOUND)

libvisual-plugins/plugins/actor/gforce/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SET(GFORCE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/plugins/actor/gforce)
22
SET(GFORCE_DATA_DIR ${LV_PLUGIN_DATA_DIR}/actor/actor_gforce)
33

44
SET(GFORCE_COMPILE_DEFS UNIX_X _REENTRANT)
5-
SET(GFORCE_COMPILE_OPTIONS -fno-strict-aliasing -Wno-unknown-warning-option -Wno-sometimes-uninitialized)
5+
SET(GFORCE_COMPILE_OPTIONS -Werror)
66

77
# Required on GCC but not Clang for some reason.
88
IF(NOT MINGW)

libvisual-plugins/plugins/actor/gforce/Common/GeneralTools/Headers/XFloatList.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,35 @@
44
// by Andrew O'Meara
55

66
#include "XPtrList.h"
7+
#include <string.h>
78

89
class XLongList;
910

11+
inline float void_ptr_to_float(const void* value)
12+
{
13+
float result;
14+
memcpy( &result, &value, sizeof( result ) );
15+
return result;
16+
}
17+
18+
inline void* float_to_void_ptr(float value)
19+
{
20+
void* result = 0;
21+
memcpy( &result, &value, sizeof( value ) );
22+
return result;
23+
}
1024

1125
class XFloatList {
1226

1327
public:
1428
XFloatList( ListOrderingT inOrdering = cOrderNotImportant ); // See XPtrList.h for ListOrderingT choices
1529

1630
// See XPtrList.h for description of functions.
17-
virtual long Add( float inNum ) { return mList.Add( *((void**) &inNum) ); }
31+
virtual long Add( float inNum ) { return mList.Add( float_to_void_ptr( inNum ) ); }
1832
virtual void Add( const XFloatList& inList ) { mList.Add( inList.mList ); }
1933
virtual bool RemoveElement( long inIndex ) { return mList.RemoveElement( inIndex ); }
2034
virtual void RemoveAll() { mList.RemoveAll(); }
21-
virtual float Fetch( long inIndex ) { long t = (long) mList.Fetch( inIndex ); return *((float*) &t);}
35+
virtual float Fetch( long inIndex ) { return void_ptr_to_float( mList.Fetch( inIndex ) ); }
2236
virtual bool Fetch( long inIndex, float* ioPtrDest ) const { return mList.Fetch( inIndex, (void**)ioPtrDest ); }
2337
virtual long Count() const { return mList.Count(); }
2438

@@ -36,7 +50,7 @@ class XFloatList {
3650
// Smoothes all the floats in this list
3751
void GaussSmooth( float inSigma );
3852

39-
float operator[] ( const long inIndex ) { long t = (long) mList.Fetch( inIndex ); return *((float*) &t); }
53+
float operator[] ( const long inIndex ) { return void_ptr_to_float(mList.Fetch( inIndex )); }
4054

4155
// Generic utility fcn to gauss-smooth a 1D curve.
4256
static void GaussSmooth( float inSigma, long inN, float inSrceDest[] );

libvisual-plugins/plugins/actor/gforce/Common/GeneralTools/XFloatList.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void XFloatList::FindMeans( long inNumMeans, float outMeans[], float inSigmaScal
6464

6565
// If this a local max. (Note: this could/should be improved for neighbors that are equal)
6666
if ( ( cen > left && cen >= right ) ) {
67-
sepCandidates.Put( i, *((void**) &cen) );
67+
sepCandidates.Put( i, float_to_void_ptr( cen ) );
6868
}
6969
}
7070

@@ -284,7 +284,7 @@ void XFloatList::Rank( XLongList& outRank, long inNumToRank ) const {
284284

285285

286286
int XFloatList::sQSFloatComparitor( const void* inA, const void* inB ) {
287-
float diff = *((float*) inB) - *((float*) inA);
287+
float diff = void_ptr_to_float(inB) - void_ptr_to_float(inA);
288288
if ( diff > 0.0 )
289289
return 1;
290290
else if ( diff < 0.0 )
@@ -296,7 +296,7 @@ int XFloatList::sQSFloatComparitor( const void* inA, const void* inB ) {
296296

297297

298298
int XFloatList::sFloatComparitor( const void* inA, const void* inB ) {
299-
float diff = *((float*) &inB) - *((float*) &inA);
299+
float diff = void_ptr_to_float(inA) - void_ptr_to_float(inB);
300300
if ( diff > 0.0 )
301301
return 1;
302302
else if ( diff < 0.0 )

libvisual-plugins/plugins/actor/gforce/Common/GeneralTools/XStrList.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ long XStrList::Add( const UtilStr& inStr ) {
9595

9696

9797
long XStrList::FetchBestMatch( const UtilStr& inStr ) {
98-
long best, bestScore, score, i;
99-
UtilStr* str;
100-
101-
best = 0;
98+
long bestScore = 0;
99+
long best = 0;
100+
UtilStr* str;
102101

103-
for ( i = 1; mStrings.Fetch( i, (void**) &str ); i++ ) {
104-
score = str -> LCSMatchScore( inStr );
102+
for ( long i = 1; mStrings.Fetch( i, (void**) &str ); i++ ) {
103+
long score = str -> LCSMatchScore( inStr );
105104
if ( score > bestScore || i == 1 ) {
106105
best = i;
107106
bestScore = score;

libvisual-plugins/plugins/actor/gforce/Common/UI/LineXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
halfW = ( tw ) >> 1;
138138

139139
if ( tw < 12 ) {
140-
const char* c_shape;
140+
const char* c_shape = nullptr;
141141
__circ( tw, c_shape )
142142
for ( j = 0; j < tw; j++ ) {
143143
c_x = c_shape[ j ];

libvisual-plugins/plugins/actor/gforce/Common/io/CEgIStream.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "CEgIStream.h"
2-
3-
//#include <string.h>
2+
#include <stdint.h>
3+
#include <string.h>
44

55

66
UtilStr CEgIStream::sTemp;
@@ -32,8 +32,20 @@ long CEgIStream::GetLong() {
3232

3333

3434
float CEgIStream::GetFloat() {
35-
long v = GetLong();
36-
return *( (float*) &v );
35+
uint32_t c, n = GetByte();
36+
37+
c = GetByte();
38+
n = n | ( c << 8 );
39+
40+
c = GetByte();
41+
n = n | ( c << 16 );
42+
43+
c = GetByte();
44+
n = n | ( c << 24 );
45+
46+
float result;
47+
memcpy(&result, &n, sizeof(result));
48+
return result;
3749
}
3850

3951

@@ -50,7 +62,7 @@ short int CEgIStream::GetShort() {
5062

5163

5264
unsigned char CEgIStream::GetByte() {
53-
unsigned char c;
65+
unsigned char c = 0;
5466

5567
if ( mIsTied ) {
5668
if ( mPos != 0 ) {
@@ -74,7 +86,7 @@ unsigned char CEgIStream::GetByte() {
7486

7587

7688
unsigned char CEgIStream::PeekByte() {
77-
unsigned char c;
89+
unsigned char c = 0;
7890

7991
if ( mIsTied ) {
8092
if ( mPos != 0 )

libvisual-plugins/plugins/actor/gforce/Common/math/ExprVirtualMachine.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <libvisual/libvisual.h>
2222
#include <limits>
2323
#include <stdlib.h>
24-
24+
#include <string.h>
2525

2626
#define __addInst( opcode, data16 ) long op = (opcode) | (data16); \
2727
mProgram.Append( &op, sizeof(long) );
@@ -85,8 +85,8 @@ ExprUserFcn ExprVirtualMachine::sZeroFcn = { 0, { 0 } };
8585
case cABS: r = fabs( r ); break; \
8686
case cSIN: r = sin( r ); break; \
8787
case cCOS: r = cos( r ); break; \
88-
case cSEED: i = *((long*) &r); \
89-
size = i % 31; \
88+
case cSEED: i = pun_float_to_int32( r ); \
89+
size = i % 31; \
9090
srand( ( i << size ) | ( i >> ( 32 - size ) ) ); break; \
9191
case cTAN: r = tan( r ); break; \
9292
case cSGN: r = ( r >= 0 ) ? 1 : -1; break; \
@@ -114,6 +114,12 @@ ExprUserFcn ExprVirtualMachine::sZeroFcn = { 0, { 0 } };
114114
case '%': { long tt = r2; r1 = (tt != 0) ? (( (long) r1 ) % tt) : 0.0; break; } \
115115
}
116116

117+
int32_t pun_float_to_int32(float x) {
118+
int32_t result = 0;
119+
memcpy( &result, &x, sizeof( result ) );
120+
return result;
121+
}
122+
117123
ExprVirtualMachine::ExprVirtualMachine() {
118124
mPCStart = 0;
119125
mPCEnd = 0;

libvisual-plugins/plugins/actor/gforce/GForceCommon/GF_Palette.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ void GF_Palette::Assign( const ArgList& inArgs ) {
4040

4141

4242
void GF_Palette::Evaluate( PixPalEntry outPalette[ 256 ] ) {
43-
int i;
44-
float H, S, V, inc = 1.0 / 255.0;
43+
float H = 0.0;
44+
float S = 0.0;
45+
float V = 0.0;
46+
float inc = 1.0 / 255.0;
4547

4648
*mIntensity = 0;
4749

@@ -50,7 +52,7 @@ void GF_Palette::Evaluate( PixPalEntry outPalette[ 256 ] ) {
5052
if ( ! mS_I_Dep ) S = mS.Evaluate();
5153
if ( ! mV_I_Dep ) V = mV.Evaluate();
5254

53-
for ( i = 0; i < 256; i++, *mIntensity += inc ) {
55+
for ( int i = 0; i < 256; i++, *mIntensity += inc ) {
5456

5557
// Don't reevaluate vars that are indep of i
5658
if ( mH_I_Dep ) H = mH.Evaluate();

0 commit comments

Comments
 (0)