Program: 31824
Project: 31824
Buggy source:
private void drawSpectrumOnCanvas(Canvas c,final double[] _db){
  if (canvasHeight < 1 || _db == null || _db.length == 0) {
    return;
  }
  AnalyzerGraphic.setIsBusy(true);
synchronized (_db) {
    if (db_cache == null || db_cache.length != _db.length) {
      Log.i(TAG,"String_Node_Str");
      db_cache=new double[_db.length];
    }
    System.arraycopy(_db,0,db_cache,0,_db.length);
  }
  float canvasMinFreq=axisX.vMinInView();
  float canvasMaxFreq=axisX.vMaxInView();
  float freqDelta=(axisX.vHigherBound - axisX.vLowerBound) / (db_cache.length - 1);
  int nFreqPointsTotal=db_cache.length - 1;
  int beginFreqPt=(int)ceil(canvasMinFreq / freqDelta);
  int endFreqPt=(int)floor(canvasMaxFreq / freqDelta) + 1;
  float minYCanvas=axisY.pixelNoZoomFromV(AnalyzerGraphic.minDB);
  if (beginFreqPt > 0) {
    beginFreqPt-=1;
  }
  if (beginFreqPt == 0 && axisX.mapTypeInt == ScreenPhysicalMapping.Type.LOG.getValue()) {
    beginFreqPt++;
  }
  if (endFreqPt < db_cache.length) {
    endFreqPt+=1;
  }
  if (tmpLineXY.length != 4 * (db_cache.length)) {
    Log.i(TAG,"String_Node_Str");
    tmpLineXY=new float[4 * (db_cache.length)];
  }
  if (showLines == false) {
    c.save();
    if (endFreqPt - beginFreqPt >= axisX.nCanvasPixel / 2 || axisX.mapTypeInt != ScreenPhysicalMapping.Type.LINEAR.getValue()) {
      matrix.reset();
      matrix.setTranslate(0,-axisY.shift * canvasHeight);
      matrix.postScale(1,axisY.zoom);
      c.concat(matrix);
      for (int i=beginFreqPt; i < endFreqPt; i++) {
        float x=axisX.pixelFromV(i * freqDelta);
        float y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[i]));
        if (y != canvasHeight) {
          tmpLineXY[4 * i]=x;
          tmpLineXY[4 * i + 1]=minYCanvas;
          tmpLineXY[4 * i + 2]=x;
          tmpLineXY[4 * i + 3]=y;
        }
      }
      c.drawLines(tmpLineXY,4 * beginFreqPt,4 * (endFreqPt - beginFreqPt),linePaint);
    }
 else {
      int pixelStep=2;
      matrix.reset();
      float extraPixelAlignOffset=0.0f;
      matrix.setTranslate(-axisX.shift * nFreqPointsTotal * pixelStep - extraPixelAlignOffset,-axisY.shift * canvasHeight);
      matrix.postScale(canvasWidth / ((canvasMaxFreq - canvasMinFreq) / freqDelta * pixelStep),axisY.zoom);
      c.concat(matrix);
      for (int i=beginFreqPt; i < endFreqPt; i++) {
        float x=i * pixelStep;
        float y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[i]));
        if (y != canvasHeight) {
          tmpLineXY[4 * i]=x;
          tmpLineXY[4 * i + 1]=minYCanvas;
          tmpLineXY[4 * i + 2]=x;
          tmpLineXY[4 * i + 3]=y;
        }
      }
      c.drawLines(tmpLineXY,4 * beginFreqPt,4 * (endFreqPt - beginFreqPt),linePaint);
    }
    c.restore();
  }
  c.save();
  matrix.reset();
  matrix.setTranslate(0,-axisY.shift * canvasHeight);
  matrix.postScale(1,axisY.zoom);
  c.concat(matrix);
  float o_x=axisX.pixelFromV(beginFreqPt * freqDelta);
  float o_y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[beginFreqPt]));
  for (int i=beginFreqPt + 1; i < endFreqPt; i++) {
    float x=axisX.pixelFromV(i * freqDelta);
    float y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[i]));
    tmpLineXY[4 * i]=o_x;
    tmpLineXY[4 * i + 1]=o_y;
    tmpLineXY[4 * i + 2]=x;
    tmpLineXY[4 * i + 3]=y;
    o_x=x;
    o_y=y;
  }
  c.drawLines(tmpLineXY,4 * (beginFreqPt + 1),4 * (endFreqPt - beginFreqPt - 1),linePaintLight);
  c.restore();
  AnalyzerGraphic.setIsBusy(false);
}

Fixed version (ground truth):
private void drawSpectrumOnCanvas(Canvas c,final double[] _db){
  if (canvasHeight < 1 || _db == null || _db.length == 0) {
    return;
  }
  AnalyzerGraphic.setIsBusy(true);
synchronized (_db) {
    if (db_cache == null || db_cache.length != _db.length) {
      Log.d(TAG,"String_Node_Str");
      db_cache=new double[_db.length];
    }
    System.arraycopy(_db,0,db_cache,0,_db.length);
  }
  float canvasMinFreq=axisX.vMinInView();
  float canvasMaxFreq=axisX.vMaxInView();
  int nFreqPointsTotal=db_cache.length - 1;
  float freqDelta=axisX.vHigherBound / nFreqPointsTotal;
  int beginFreqPt=(int)floor(canvasMinFreq / freqDelta);
  int endFreqPt=(int)ceil(canvasMaxFreq / freqDelta) + 1;
  final float minYCanvas=axisY.pixelNoZoomFromV(AnalyzerGraphic.minDB);
  if (beginFreqPt == 0 && axisX.mapTypeInt == ScreenPhysicalMapping.Type.LOG.getValue()) {
    beginFreqPt++;
  }
  if (endFreqPt > db_cache.length) {
    endFreqPt=db_cache.length;
  }
  if (tmpLineXY.length != 4 * (db_cache.length)) {
    Log.d(TAG,"String_Node_Str");
    tmpLineXY=new float[4 * (db_cache.length)];
  }
  if (showLines == false) {
    c.save();
    if (endFreqPt - beginFreqPt >= axisX.nCanvasPixel / 2 || axisX.mapTypeInt != ScreenPhysicalMapping.Type.LINEAR.getValue()) {
      matrix.reset();
      matrix.setTranslate(0,-axisY.shift * canvasHeight);
      matrix.postScale(1,axisY.zoom);
      c.concat(matrix);
      for (int i=beginFreqPt; i < endFreqPt; i++) {
        float x=axisX.pixelFromV(i * freqDelta);
        float y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[i]));
        if (y != canvasHeight) {
          tmpLineXY[4 * i]=x;
          tmpLineXY[4 * i + 1]=minYCanvas;
          tmpLineXY[4 * i + 2]=x;
          tmpLineXY[4 * i + 3]=y;
        }
      }
      c.drawLines(tmpLineXY,4 * beginFreqPt,4 * (endFreqPt - beginFreqPt),linePaint);
    }
 else {
      int pixelStep=2;
      matrix.reset();
      float extraPixelAlignOffset=0.0f;
      matrix.setTranslate(-axisX.shift * nFreqPointsTotal * pixelStep - extraPixelAlignOffset,-axisY.shift * canvasHeight);
      matrix.postScale(canvasWidth / ((canvasMaxFreq - canvasMinFreq) / freqDelta * pixelStep),axisY.zoom);
      c.concat(matrix);
      for (int i=beginFreqPt; i < endFreqPt; i++) {
        float x=i * pixelStep;
        float y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[i]));
        if (y != canvasHeight) {
          tmpLineXY[4 * i]=x;
          tmpLineXY[4 * i + 1]=minYCanvas;
          tmpLineXY[4 * i + 2]=x;
          tmpLineXY[4 * i + 3]=y;
        }
      }
      c.drawLines(tmpLineXY,4 * beginFreqPt,4 * (endFreqPt - beginFreqPt),linePaint);
    }
    c.restore();
  }
  c.save();
  matrix.reset();
  matrix.setTranslate(0,-axisY.shift * canvasHeight);
  matrix.postScale(1,axisY.zoom);
  c.concat(matrix);
  float o_x=axisX.pixelFromV(beginFreqPt * freqDelta);
  float o_y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[beginFreqPt]));
  for (int i=beginFreqPt + 1; i < endFreqPt; i++) {
    float x=axisX.pixelFromV(i * freqDelta);
    float y=axisY.pixelNoZoomFromV(clampDB((float)db_cache[i]));
    tmpLineXY[4 * i]=o_x;
    tmpLineXY[4 * i + 1]=o_y;
    tmpLineXY[4 * i + 2]=x;
    tmpLineXY[4 * i + 3]=y;
    o_x=x;
    o_y=y;
  }
  c.drawLines(tmpLineXY,4 * (beginFreqPt + 1),4 * (endFreqPt - beginFreqPt - 1),linePaintLight);
  c.restore();
  AnalyzerGraphic.setIsBusy(false);
}