Uninitialised value in cmp function qsort

I'm trying to understand what's wrong with this code:

int myCompare( const void * v1, const void * v2 ){
   const int * f1 = static_cast<const int *>(v1);
   const int * f2 = static_cast<const int *>(v2);
   if( f1[ 0 ] < f2[ 0 ] ) return -1;
   if( f1[ 0 ] > f2[ 0 ] ) return +1;
   return 0;

This is a comparator function for qsort it work's fine but when I've profiled it with valgrind I have this message in this strings Conditional jump or move depends on uninitialised value(s)

 if( f1[ 0 ] < f2[ 0 ] ) return -1;
 if( f1[ 0 ] > f2[ 0 ] ) return +1;

qsort is calling from here

valgrind output

==25053== Conditional jump or move depends on uninitialised value(s)
==25053==    at 0x66474CB: msort_with_tmp.part.0 (msort.c:83)
==25053==    by 0x6647221: msort_with_tmp.part.0 (msort.c:45)
==25053==    by 0x6647221: msort_with_tmp.part.0 (msort.c:45)
==25053==    by 0x664777B: qsort_r (msort.c:45)
==25053==    by 0x40D002: owOpenCLSolver::_runSort(owConfigProrerty*)(owOpenCLSolver.cpp:473)
==25053==    by 0x4114DB: owPhysicsFluidSimulator::simulationStep(bool) (owPhysicsFluidSimulator.cpp:186)
==25053==    by 0x412FBC: run(int, char**, bool) (owWorldSimulation.cpp:919)
==25053==    by 0x4058D4: main (main.cpp:95)
==25053==  Uninitialised value was created by a client request
==25053==    at 0xA6AF9F8: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA69BF40: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA3DCB0F: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA42DECA: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA37E03F: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA3558D0: ??? (in /usr/lib/libamdocl64.so)enter code here
==25053==    by 0xA35A1C1: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA35A2EC: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA32972D: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA2D095E: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0xA337AEB: ??? (in /usr/lib/libamdocl64.so)
==25053==    by 0x6BDD181: start_thread (pthread_create.c:312)


Actually In class owOpenCLSolver where I'm using this sort function I have no one places where buffer _particleIndex(buffer which will be sort than) is initializing explicitly but initialization is going in function copy_buffer_from_device which is copying data from OpenCL device into a host programm buffer. So may be the problem is in that valgrind doesn't think that _particleIndex isn't init when function is using it.


Valgrind traces memory reads and writes and I think here it's telling you that the function happened to be called with at least one pointer to memory that's never been written to, as of the moment of the call.

Need Your Help

Is a one column table good design?

sql database-design

It it ok to have a table with just one column? I know it isn't technically illegal, but is it considered poor design?

How to modify delphi property Getter/Setter with RTTI?

delphi rtti delphi-xe5

I would like to replace the getter/setter for properties using RTTI.