OpenHantek / OpenHantek6022

OpenHantek6022 is a DSO software for Hantek USB digital signal oscilloscopes 6022BE / BL. Development OS is Debian Linux, but the program also works on FreeBSD, MacOS, RaspberryPi and Windows. No support for non-Linux related issues unless a volunteer steps in!
GNU General Public License v3.0
868 stars 153 forks source link

division by zero #75

Closed LubuntuSharp closed 4 years ago

LubuntuSharp commented 4 years ago

Describe the bug A division by zero comes out

To Reproduce GDB SHOWS OpenHantek6022-3.0.3/openhantek/src/hantekdso/hantekdsocontrol.cpp LINE 549 result.data[channel].resize( sampleCount / rawDownsampling ); rawDownsampling can happen to be equal to zero at run-time (I solved by defaulting resize argument to 1 instead of getting division by zero)

System info:

Scope device (please complete the following information):

Additional context I run with --useGLES option

Ho-Ro commented 4 years ago

ok, from data flow it shouldn't happen:

unsigned HantekDsoControl::getRecordLength() const {
    unsigned rawsize = SAMPLESIZE_USED; // = 20000
    rawsize *= this->downsamplingNumber; // take more samples
    rawsize = ( (rawsize + 1024) / 1024 + 2 ) * 1024; // adjust for skipping of minimal 2018 leading samples
    //printf( "getRecordLength: %d\n", rawsize );
    return rawsize;
}

...

const unsigned rawSampleCount = unsigned( isFastRate() ? rawData.size() : (rawData.size() / 2) );
//printf("cRDTS, rawSampleCount %lu\n", rawSampleCount);
if ( 0 == rawSampleCount) // nothing to convert
    return;
...
unsigned sampleCount = (rawSampleCount > 1024) ? ((rawSampleCount - 1024)/1000 - 1)*1000 : rawSampleCount;
...
unsigned rawDownsampling = sampleCount / SAMPLESIZE_USED;
....
result.data[channel].resize( sampleCount / rawDownsampling );

but I've included more safeguarding with a933b52