Program: 72569
Project: 72569
Buggy source:
/** 
 * Write to the GCL. <p>Usage:<code> DYLD_LIBRARY_PATH=${PTII}/org/terraswarm/gdp/src/gdp/libs:/usr/local/lib LD_LIBRARY_PATH=${PTII}/org/terraswarm/gdp/src/gdp/libs:/usr/local/lib $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.ReaderTest elvis</code></p> <p>The arguments below are optional:</p> <p><code>-D <i>debuggingSpecification</i></code>, where an example of <i>debuggingSpecifiction</i> is, <code>gdp.api=100</code>.  See the gdp .c files for debugging specifications</p>. <p><code>-G <i>gdpdAddress</i></code>, which names the IP address and port name of the gdp daemon (<code>gdpd</code>) where an example of <i>gdpdAddress</i> is <code>127.0.0.1:2468</code>.  If <code>-G</code> is not present, then the default address of <code>127.0.0.1:2468</code> is used. <p><code>-a</code> FIXME: what does this do?</p> <p><code><i>gcl_name</i></code> The name of the gcl.  This string is used with ReaderTest</p>
 * @param argv The command line arguments, documented above.
 */
public static void main(String[] argv) throws Throwable {
  Native.setProtected(true);
  _debug("String_Node_Str" + Native.isProtected());
  Pointer gclh=null;
  ByteBuffer gcliname=ByteBuffer.allocate(32);
  EP_STAT estat;
  boolean append=false;
  String gdpd_addr=null;
  String xname=null;
  int argc=argv.length;
  for (int i=0; i < argv.length; i++) {
    if (argv[i].equals("String_Node_Str")) {
      append=true;
      argc--;
    }
 else     if (argv[i].equals("String_Node_Str")) {
      argc--;
      Gdp10Library.INSTANCE.ep_dbg_set(argv[i + 1]);
      argc--;
    }
 else     if (argv[i].equals("String_Node_Str")) {
      argc--;
      gdpd_addr=argv[i + 1];
      argc--;
    }
  }
  _debug("String_Node_Str" + argv.length + "String_Node_Str"+ argc);
  if (argc > 0) {
    xname=argv[argv.length - 1];
    argc--;
  }
  if (argc != 0 || (append && xname == null)) {
    System.err.println("String_Node_Str" + "String_Node_Str");
    _debug("String_Node_Str" + argc + "String_Node_Str"+ append+ "String_Node_Str"+ (xname == null ? "String_Node_Str" : xname));
    System.exit(64);
  }
  _debug("String_Node_Str");
  estat=Gdp10Library.INSTANCE.gdp_init(gdpd_addr);
  if (!GdpUtilities.EP_STAT_ISOK(estat)) {
    System.err.println("String_Node_Str");
    _fail0(estat);
  }
  _debug("String_Node_Str");
  if (xname == null) {
    _debug("String_Node_Str");
    PointerByReference gclhByReference=new PointerByReference();
    estat=Gdp10Library.INSTANCE.gdp_gcl_create((ByteBuffer)null,gclhByReference);
    gclh=gclhByReference.getValue();
    _debug("String_Node_Str" + estat);
    _debug("String_Node_Str" + gclh);
  }
 else {
    _debug("String_Node_Str" + xname);
    Gdp10Library.INSTANCE.gdp_gcl_parse_name(xname,gcliname);
    if (append) {
      _debug("String_Node_Str");
      PointerByReference gclhByReference=new PointerByReference();
      estat=Gdp10Library.INSTANCE.gdp_gcl_open(gcliname,Gdp10Library.gdp_iomode_t.GDP_MODE_AO,gclhByReference);
      gclh=gclhByReference.getValue();
    }
 else {
      _debug("String_Node_Str");
      PointerByReference gclhByReference=new PointerByReference();
      estat=Gdp10Library.INSTANCE.gdp_gcl_create(gcliname,gclhByReference);
      gclh=gclhByReference.getValue();
    }
  }
  _debug("String_Node_Str");
  if (!GdpUtilities.EP_STAT_ISOK(estat)) {
    _fail0(estat);
  }
  _debug("String_Node_Str" + System.identityHashCode(gclh) + "String_Node_Str");
  System.out.println("String_Node_Str");
  _debug("String_Node_Str");
  PointerByReference datum=Gdp10Library.INSTANCE.gdp_datum_new();
  _debug("String_Node_Str");
  _debug("String_Node_Str" + datum);
  BufferedReader bufferedReader=null;
  try {
    bufferedReader=new BufferedReader(new InputStreamReader(System.in));
    String line;
    final int bufferLength=200;
    while ((line=bufferedReader.readLine()) != null) {
      System.out.println("String_Node_Str" + line + "String_Node_Str");
      if (line.length() > bufferLength) {
        throw new Exception("String_Node_Str" + line + "String_Node_Str"+ bufferLength);
      }
      Memory memory=new Memory(bufferLength);
      Memory alignedMemory=memory.align(4);
      memory.clear();
      Pointer pointer=alignedMemory.share(0);
      pointer.setString(0,line);
      _debug("String_Node_Str");
      PointerByReference dbuf=Gdp10Library.INSTANCE.gdp_datum_getbuf(datum);
      _debug("String_Node_Str" + pointer + "String_Node_Str"+ pointer.getString(0));
      Gdp10Library.INSTANCE.gdp_buf_write(dbuf,pointer,new NativeSizeT(line.length()));
      _debug("String_Node_Str");
      _debug("String_Node_Str" + gclh);
      _debug("String_Node_Str" + datum);
      GdpUtilities.gdp_datum_print(datum);
      estat=Gdp10Library.INSTANCE.gdp_gcl_publish(gclh,datum);
      if (!GdpUtilities.EP_STAT_ISOK(estat)) {
        PointerByReference gclhByReference=new PointerByReference();
        _fail1(estat,gclhByReference);
        gclh=gclhByReference.getValue();
      }
      _debug("String_Node_Str");
      GdpUtilities.gdp_datum_print(datum);
    }
  }
  finally {
    if (bufferedReader != null) {
      bufferedReader.close();
    }
  }
  Gdp10Library.INSTANCE.gdp_datum_free(datum);
  _fail0(estat);
}

Fixed version (ground truth):
/** 
 * Write to the GCL. <p>Usage:<code> DYLD_LIBRARY_PATH=${PTII}/org/terraswarm/gdp/src/gdp/libs:/usr/local/lib LD_LIBRARY_PATH=${PTII}/org/terraswarm/gdp/src/gdp/libs:/usr/local/lib $(JAVA) -Djna.debug_load=true -Djna.dump_memory=true -classpath $(CLASSPATH) org.terraswarm.gdp.apps.ReaderTest elvis</code></p> <p>The arguments below are optional:</p> <p><code>-D <i>debuggingSpecification</i></code>, where an example of <i>debuggingSpecifiction</i> is, <code>gdp.api=100</code>.  See the gdp .c files for debugging specifications</p>. <p><code>-G <i>gdpdAddress</i></code>, which names the IP address and port name of the gdp daemon (<code>gdpd</code>) where an example of <i>gdpdAddress</i> is <code>127.0.0.1:2468</code>.  If <code>-G</code> is not present, then the default address of <code>127.0.0.1:2468</code> is used. <p><code>-a</code> FIXME: what does this do?</p> <p><code><i>gcl_name</i></code> The name of the gcl.  This string is used with ReaderTest</p>
 * @param argv The command line arguments, documented above.
 */
public static void main(String[] argv) throws Throwable {
  Native.setProtected(true);
  _debug("String_Node_Str" + Native.isProtected());
  Pointer gclh=null;
  ByteBuffer gcliname=ByteBuffer.allocate(32);
  EP_STAT estat;
  boolean append=false;
  String gdpd_addr=null;
  String xname=null;
  int argc=argv.length;
  for (int i=0; i < argv.length; i++) {
    if (argv[i].equals("String_Node_Str")) {
      append=true;
      argc--;
    }
 else     if (argv[i].equals("String_Node_Str")) {
      argc--;
      Gdp10Library.INSTANCE.ep_dbg_set(argv[i + 1]);
      argc--;
    }
 else     if (argv[i].equals("String_Node_Str")) {
      argc--;
      gdpd_addr=argv[i + 1];
      argc--;
    }
  }
  _debug("String_Node_Str" + argv.length + "String_Node_Str"+ argc);
  if (argc > 0) {
    xname=argv[argv.length - 1];
    argc--;
  }
  if (argc != 0 || (append && xname == null)) {
    System.err.println("String_Node_Str" + "String_Node_Str");
    _debug("String_Node_Str" + argc + "String_Node_Str"+ append+ "String_Node_Str"+ (xname == null ? "String_Node_Str" : xname));
    System.exit(64);
  }
  _debug("String_Node_Str");
  estat=Gdp10Library.INSTANCE.gdp_init(gdpd_addr);
  if (!GdpUtilities.EP_STAT_ISOK(estat)) {
    System.err.println("String_Node_Str");
    _fail0(estat);
  }
  _debug("String_Node_Str");
  if (xname == null) {
    _debug("String_Node_Str");
    PointerByReference gclhByReference=new PointerByReference();
    estat=Gdp10Library.INSTANCE.gdp_gcl_create((ByteBuffer)null,gclhByReference);
    gclh=gclhByReference.getValue();
    _debug("String_Node_Str" + estat);
    _debug("String_Node_Str" + gclh);
  }
 else {
    _debug("String_Node_Str" + xname);
    Gdp10Library.INSTANCE.gdp_gcl_parse_name(xname,gcliname);
    if (append) {
      _debug("String_Node_Str");
      PointerByReference gclhByReference=new PointerByReference();
      estat=Gdp10Library.INSTANCE.gdp_gcl_open(gcliname,Gdp10Library.gdp_iomode_t.GDP_MODE_AO,gclhByReference);
      gclh=gclhByReference.getValue();
    }
 else {
      _debug("String_Node_Str");
      PointerByReference gclhByReference=new PointerByReference();
      estat=Gdp10Library.INSTANCE.gdp_gcl_create(gcliname,gclhByReference);
      gclh=gclhByReference.getValue();
    }
  }
  _debug("String_Node_Str");
  if (!GdpUtilities.EP_STAT_ISOK(estat)) {
    _fail0(estat);
  }
  _debug("String_Node_Str" + System.identityHashCode(gclh) + "String_Node_Str");
  System.out.println("String_Node_Str");
  _debug("String_Node_Str");
  PointerByReference datum=Gdp10Library.INSTANCE.gdp_datum_new();
  _debug("String_Node_Str");
  _debug("String_Node_Str" + datum);
  BufferedReader bufferedReader=null;
  try {
    bufferedReader=new BufferedReader(new InputStreamReader(System.in,java.nio.charset.Charset.defaultCharset()));
    String line;
    final int bufferLength=200;
    while ((line=bufferedReader.readLine()) != null) {
      System.out.println("String_Node_Str" + line + "String_Node_Str");
      if (line.length() > bufferLength) {
        throw new Exception("String_Node_Str" + line + "String_Node_Str"+ bufferLength);
      }
      Memory memory=new Memory(bufferLength);
      Memory alignedMemory=memory.align(4);
      memory.clear();
      Pointer pointer=alignedMemory.share(0);
      pointer.setString(0,line);
      _debug("String_Node_Str");
      PointerByReference dbuf=Gdp10Library.INSTANCE.gdp_datum_getbuf(datum);
      _debug("String_Node_Str" + pointer + "String_Node_Str"+ pointer.getString(0));
      Gdp10Library.INSTANCE.gdp_buf_write(dbuf,pointer,new NativeSizeT(line.length()));
      _debug("String_Node_Str");
      _debug("String_Node_Str" + gclh);
      _debug("String_Node_Str" + datum);
      GdpUtilities.gdp_datum_print(datum);
      estat=Gdp10Library.INSTANCE.gdp_gcl_publish(gclh,datum);
      if (!GdpUtilities.EP_STAT_ISOK(estat)) {
        PointerByReference gclhByReference=new PointerByReference();
        _fail1(estat,gclhByReference);
        gclh=gclhByReference.getValue();
      }
      _debug("String_Node_Str");
      GdpUtilities.gdp_datum_print(datum);
    }
  }
  finally {
    if (bufferedReader != null) {
      bufferedReader.close();
    }
  }
  Gdp10Library.INSTANCE.gdp_datum_free(datum);
  _fail0(estat);
}