Program: 74348
Project: 74348
Buggy source:
/** 
 * Parse from the _parseIndex and return the next code block body from the given StringBuffer. This method recursively parses within the code body for nested code blocks.
 * @param codeInFile Code from the helper .c file.
 * @return The code body within the current code block.
 * @exception IllegalActionException If code block's close blockpattern, _BLOCKEND, is missing.
 * @see _parseIndex
 * @see _BLOCKEND
 */
private StringBuffer _parseBody(StringBuffer codeInFile) throws IllegalActionException {
  int openBlock=1;
  int scanIndex=_parseIndex;
  int startIndex;
  int endIndex=-1;
  while (openBlock > 0) {
    endIndex=codeInFile.indexOf(_BLOCKEND,scanIndex);
    startIndex=codeInFile.indexOf(_BLOCKSTART,scanIndex);
    if ((startIndex < endIndex) && (startIndex != -1)) {
      openBlock++;
      scanIndex=startIndex + 1;
    }
 else {
      openBlock--;
      scanIndex=endIndex + 1;
    }
  }
  if (endIndex == -1) {
    throw new IllegalActionException("String_Node_Str" + _filePath);
  }
  StringBuffer body=new StringBuffer(codeInFile.substring(_parseIndex,endIndex));
  while (body.length() > 0 && (body.charAt(0) == '\n' || body.charAt(0) == '\r' || body.charAt(0) == ' ')) {
    body.deleteCharAt(0);
  }
  int endChar=body.length() - 1;
  while (endChar >= 0 && (body.charAt(endChar) == '\n' || body.charAt(endChar) == '\r' || body.charAt(endChar) == ' ')) {
    body.deleteCharAt(endChar);
    endChar=body.length() - 1;
  }
  body.append(_eol);
  _parseIndex=_BLOCKEND.length() + endIndex;
  return body;
}

Fixed version (ground truth):
/** 
 * Parse from the _parseIndex and return the next code block body from the given StringBuffer. This method recursively parses within the code body for nested code blocks.
 * @param codeInFile Code from the helper .c file.
 * @return The code body within the current code block.
 * @exception IllegalActionException If code block's close blockpattern, _BLOCKEND, is missing.
 * @see _parseIndex
 * @see _BLOCKEND
 */
private StringBuffer _parseBody(StringBuffer codeInFile) throws IllegalActionException {
  int openBlock=1;
  int scanIndex=_parseIndex;
  int startIndex;
  int endIndex=-1;
  while (openBlock > 0) {
    endIndex=codeInFile.indexOf(_BLOCKEND,scanIndex);
    startIndex=codeInFile.indexOf(_BLOCKSTART,scanIndex);
    if ((startIndex < endIndex) && (startIndex != -1)) {
      openBlock++;
      scanIndex=startIndex + 1;
    }
 else {
      openBlock--;
      scanIndex=endIndex + 1;
    }
  }
  if (endIndex == -1) {
    throw new IllegalActionException("String_Node_Str" + _filePath);
  }
  StringBuffer body=new StringBuffer(codeInFile.substring(_parseIndex,endIndex));
  while (body.length() > 0 && (body.charAt(0) == '\n' || body.charAt(0) == '\r' || body.charAt(0) == ' ')) {
    body.deleteCharAt(0);
  }
  boolean hasNewline=false;
  int endChar=body.length() - 1;
  while (endChar >= 0 && (body.charAt(endChar) == '\n' || body.charAt(endChar) == '\r' || body.charAt(endChar) == ' ')) {
    body.deleteCharAt(endChar);
    endChar=body.length() - 1;
    hasNewline=true;
  }
  if (hasNewline) {
    body.append(_eol);
  }
  _parseIndex=_BLOCKEND.length() + endIndex;
  return body;
}