Program: 54990
Project: 54990
Buggy source:
/** 
 * This method will draw the frequency grid into the canvas
 * @param c				canvas of the surface view
 */
private void drawFrequencyGrid(Canvas c){
  String frequencyStr;
  double MHZ=1000000F;
  double tickFreqMHz;
  float lastTextEndPos=-99999;
  float textPos;
  Rect bounds=new Rect();
  textPaint.getTextBounds("String_Node_Str",0,2,bounds);
  float minFreeSpaceBetweenText=bounds.width();
  int tickSize=10;
  float helperVar=virtualSampleRate / 20f;
  while (helperVar > 100) {
    helperVar=helperVar / 10f;
    tickSize=tickSize * 10;
  }
  float pixelPerMinorTick=width / (virtualSampleRate / (float)tickSize);
  long startFrequency=(long)(virtualFrequency - (virtualSampleRate / 2.0));
  long tickFreq=(long)(Math.ceil((double)startFrequency / (float)tickSize) * tickSize);
  float tickPos=pixelPerMinorTick / (float)tickSize * (tickFreq - startFrequency);
  for (int i=0; i < virtualSampleRate / (float)tickSize; i++) {
    float tickHeight;
    if (tickFreq % (tickSize * 10) == 0) {
      tickHeight=(float)(getGridSize() / 2.0);
      tickFreqMHz=tickFreq / MHZ;
      if (tickFreqMHz == (int)tickFreqMHz)       frequencyStr=String.format("String_Node_Str",(int)tickFreqMHz);
 else       frequencyStr=String.format("String_Node_Str",tickFreqMHz);
      textPaint.getTextBounds(frequencyStr,0,frequencyStr.length(),bounds);
      textPos=tickPos - bounds.width() / 2;
      if (lastTextEndPos + minFreeSpaceBetweenText < textPos) {
        c.drawText(frequencyStr,textPos,getFftHeight() - tickHeight,textPaint);
        lastTextEndPos=textPos + bounds.width();
      }
    }
 else     if (tickFreq % (tickSize * 5) == 0) {
      tickHeight=(float)(getGridSize() / 3.0);
      tickFreqMHz=tickFreq / MHZ;
      if (tickFreqMHz == (int)tickFreqMHz)       frequencyStr=String.format("String_Node_Str",(int)tickFreqMHz);
 else       frequencyStr=String.format("String_Node_Str",tickFreqMHz);
      textPaint.getTextBounds(frequencyStr,0,frequencyStr.length(),bounds);
      textPos=tickPos - bounds.width() / 2;
      if (lastTextEndPos + minFreeSpaceBetweenText < textPos) {
        if (bounds.width() < pixelPerMinorTick * 4) {
          c.drawText(frequencyStr,textPos,getFftHeight() - tickHeight,textPaint);
          lastTextEndPos=textPos + bounds.width();
        }
      }
    }
 else {
      tickHeight=(float)(getGridSize() / 4.0);
    }
    c.drawLine(tickPos,getFftHeight(),tickPos,getFftHeight() - tickHeight,textPaint);
    tickFreq+=tickSize;
    tickPos+=pixelPerMinorTick;
  }
}

Fixed version (ground truth):
/** 
 * This method will draw the frequency grid into the canvas
 * @param c				canvas of the surface view
 */
private void drawFrequencyGrid(Canvas c){
  String textStr;
  double MHZ=1000000F;
  double tickFreqMHz;
  float lastTextEndPos=-99999;
  float textPos;
  Rect bounds=new Rect();
  textPaint.getTextBounds("String_Node_Str",0,2,bounds);
  float minFreeSpaceBetweenText=bounds.width();
  int tickSize=10;
  float helperVar=virtualSampleRate / 20f;
  while (helperVar > 100) {
    helperVar=helperVar / 10f;
    tickSize=tickSize * 10;
  }
  float pixelPerMinorTick=width / (virtualSampleRate / (float)tickSize);
  long startFrequency=(long)(virtualFrequency - (virtualSampleRate / 2.0));
  long tickFreq=(long)(Math.ceil((double)startFrequency / (float)tickSize) * tickSize);
  float tickPos=pixelPerMinorTick / (float)tickSize * (tickFreq - startFrequency);
  for (int i=0; i < virtualSampleRate / (float)tickSize; i++) {
    float tickHeight;
    if (tickFreq % (tickSize * 10) == 0) {
      tickHeight=(float)(getGridSize() / 2.0);
      tickFreqMHz=tickFreq / MHZ;
      if (tickFreqMHz == (int)tickFreqMHz)       textStr=String.format("String_Node_Str",(int)tickFreqMHz);
 else       textStr=String.format("String_Node_Str",tickFreqMHz);
      textPaint.getTextBounds(textStr,0,textStr.length(),bounds);
      textPos=tickPos - bounds.width() / 2;
      if (lastTextEndPos + minFreeSpaceBetweenText < textPos) {
        c.drawText(textStr,textPos,getFftHeight() - tickHeight,textPaint);
        lastTextEndPos=textPos + bounds.width();
      }
    }
 else     if (tickFreq % (tickSize * 5) == 0) {
      tickHeight=(float)(getGridSize() / 3.0);
      tickFreqMHz=tickFreq / MHZ;
      if (tickFreqMHz == (int)tickFreqMHz)       textStr=String.format("String_Node_Str",(int)tickFreqMHz);
 else       textStr=String.format("String_Node_Str",tickFreqMHz);
      textPaint.getTextBounds(textStr,0,textStr.length(),bounds);
      textPos=tickPos - bounds.width() / 2;
      if (lastTextEndPos + minFreeSpaceBetweenText < textPos) {
        if (bounds.width() < pixelPerMinorTick * 4) {
          c.drawText(textStr,textPos,getFftHeight() - tickHeight,textPaint);
          lastTextEndPos=textPos + bounds.width();
        }
      }
    }
 else {
      tickHeight=(float)(getGridSize() / 4.0);
    }
    c.drawLine(tickPos,getFftHeight(),tickPos,getFftHeight() - tickHeight,textPaint);
    tickFreq+=tickSize;
    tickPos+=pixelPerMinorTick;
  }
  if (demodulationEnabled) {
    float pxPerHz=width / (float)virtualSampleRate;
    float channelPosition=width / 2 + pxPerHz * (channelFrequency - virtualFrequency);
    float leftBorder=channelPosition - pxPerHz * channelWidth;
    float rightBorder=channelPosition + pxPerHz * channelWidth;
    float dbWidth=getFftHeight() / (maxDB - minDB);
    float squelchPosition=getFftHeight() - (squelch - minDB) * dbWidth;
    demodSelectorPaint.setAlpha(0x7f);
    c.drawRect(leftBorder,0,rightBorder,squelchPosition,demodSelectorPaint);
    demodSelectorPaint.setAlpha(0xff);
    c.drawLine(channelPosition,getFftHeight(),channelPosition,0,demodSelectorPaint);
    c.drawLine(leftBorder,getFftHeight(),leftBorder,0,demodSelectorPaint);
    c.drawLine(rightBorder,getFftHeight(),rightBorder,0,demodSelectorPaint);
    c.drawLine(leftBorder,squelchPosition,rightBorder,squelchPosition,squelchPaint);
    textStr=String.format("String_Node_Str",squelch);
    textPaint.getTextBounds(textStr,0,textStr.length(),bounds);
    c.drawText(textStr,channelPosition - bounds.width() / 2f,squelchPosition - bounds.height() * 0.1f,textPaint);
    textStr=String.format("String_Node_Str",channelWidth * 2 / 1000);
    textPaint.getTextBounds(textStr,0,textStr.length(),bounds);
    c.drawText(textStr,channelPosition - bounds.width() / 2f,squelchPosition + bounds.height() * 1.1f,textPaint);
  }
}