Program: 60242
Project: 60242
Buggy source:
@Override public List<purejavahidapi.HidDeviceInfo> enumerateDevices(){
  try {
    List<purejavahidapi.HidDeviceInfo> list=new LinkedList<purejavahidapi.HidDeviceInfo>();
    GUID InterfaceClassGuid=new GUID(0x4d1e55b2,0xf16f,0x11cf,0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30);
    SP_DEVINFO_DATA devinfo_data=new SP_DEVINFO_DATA();
    SP_DEVICE_INTERFACE_DATA device_interface_data=new SP_DEVICE_INTERFACE_DATA();
    SP_DEVICE_INTERFACE_DETAIL_DATA_A device_interface_detail_data=null;
    HDEVINFO device_info_set=null;
    int deviceIndex=0;
    int i;
    devinfo_data.cbSize=devinfo_data.size();
    device_interface_data.cbSize=device_interface_data.size();
    device_info_set=SetupDiGetClassDevs(InterfaceClassGuid,null,null,DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
    for (; ; ) {
      HANDLE devHandle=INVALID_HANDLE_VALUE;
      if (!SetupDiEnumDeviceInterfaces(device_info_set,null,InterfaceClassGuid,deviceIndex,device_interface_data)) {
        if (GetLastError() == ERROR_NO_MORE_ITEMS)         break;
        reportLastError();
      }
      ;
      int[] required_size={0};
      if (!SetupDiGetDeviceInterfaceDetail(device_info_set,device_interface_data,null,0,required_size,null)) {
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)         reportLastError();
      }
      device_interface_detail_data=new SP_DEVICE_INTERFACE_DETAIL_DATA_A(required_size[0]);
      if (!SetupDiGetDeviceInterfaceDetail(device_info_set,device_interface_data,device_interface_detail_data,required_size[0],null,null))       reportLastError();
      char[] driverNameChars=new char[256];
      if (!SetupDiEnumDeviceInfo(device_info_set,deviceIndex,devinfo_data)) {
        reportLastError();
        continue;
      }
      if (!SetupDiGetDeviceRegistryProperty(device_info_set,devinfo_data,SPDRP_CLASS,null,driverNameChars,driverNameChars.length,null)) {
        reportLastError();
        continue;
      }
      int driverNameLen=0;
      while (driverNameChars[driverNameLen++] != 0)       ;
      String drivername=new String(driverNameChars,0,driverNameLen - 1);
      if ("String_Node_Str".equals(drivername)) {
        if (!SetupDiGetDeviceRegistryProperty(device_info_set,devinfo_data,SPDRP_DRIVER,null,driverNameChars,driverNameChars.length,null)) {
          if (GetLastError() != ERROR_INVALID_DATA)           reportLastError();
          continue;
        }
        char[] deviceIdChars=new char[256];
        int[] deviceIdLen={0};
        if (!SetupDiGetDeviceInstanceId(device_info_set,devinfo_data,deviceIdChars,deviceIdChars.length,deviceIdLen))         reportLastError();
        String deviceId=new String(deviceIdChars);
        int[] parent={devinfo_data.DevInst};
        while (CM_Get_Parent(parent,parent[0],0) == 0) {
          int[] parentIdLen={0};
          if (CM_Get_Device_ID_Size(parentIdLen,parent[0],0) != CR_SUCCESS)           reportLastError();
          parentIdLen[0]++;
          char[] parentIdChars=new char[parentIdLen[0]];
          if (CM_Get_Device_ID(parent[0],parentIdChars,parentIdLen[0],0) != CR_SUCCESS)           reportLastError();
          String parentId=new String(parentIdChars,0,parentIdLen[0] - 1);
          if (parentId.startsWith("String_Node_Str")) {
            deviceId=parentId;
            break;
          }
        }
        String path=new String(device_interface_detail_data.DevicePath);
        devHandle=openDeviceHandle(path,true);
        if (devHandle == INVALID_HANDLE_VALUE)         break;
        HIDD_ATTRIBUTES attrib=new HIDD_ATTRIBUTES();
        attrib.Size=new NativeLong(attrib.size());
        HidD_GetAttributes(devHandle,attrib);
        list.add(new HidDeviceInfo(path,deviceId,devHandle,attrib));
        CloseHandle(devHandle);
      }
      deviceIndex++;
    }
    SetupDiDestroyDeviceInfoList(device_info_set);
    return list;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}

Fixed version (ground truth):
@Override public List<purejavahidapi.HidDeviceInfo> enumerateDevices(){
  try {
    List<purejavahidapi.HidDeviceInfo> list=new LinkedList<purejavahidapi.HidDeviceInfo>();
    GUID InterfaceClassGuid=new GUID(0x4d1e55b2,0xf16f,0x11cf,0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30);
    SP_DEVINFO_DATA devinfo_data=new SP_DEVINFO_DATA();
    SP_DEVICE_INTERFACE_DATA device_interface_data=new SP_DEVICE_INTERFACE_DATA();
    SP_DEVICE_INTERFACE_DETAIL_DATA_A device_interface_detail_data=null;
    HDEVINFO device_info_set=null;
    devinfo_data.cbSize=devinfo_data.size();
    device_interface_data.cbSize=device_interface_data.size();
    device_info_set=SetupDiGetClassDevs(InterfaceClassGuid,null,null,DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
    for (int deviceIndex=0; ; deviceIndex++) {
      HANDLE devHandle=INVALID_HANDLE_VALUE;
      if (!SetupDiEnumDeviceInterfaces(device_info_set,null,InterfaceClassGuid,deviceIndex,device_interface_data)) {
        if (GetLastError() == ERROR_NO_MORE_ITEMS)         break;
        reportLastError();
      }
      int[] required_size={0};
      if (!SetupDiGetDeviceInterfaceDetail(device_info_set,device_interface_data,null,0,required_size,null)) {
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)         reportLastError();
      }
      int[] cbSize={8,6,5};
      for (int i=0; i < cbSize.length; i++) {
        device_interface_detail_data=new SP_DEVICE_INTERFACE_DETAIL_DATA_A(cbSize[i],required_size[0]);
        if (SetupDiGetDeviceInterfaceDetail(device_info_set,device_interface_data,device_interface_detail_data,required_size[0],null,null))         break;
        device_interface_detail_data=null;
        if (GetLastError() == ERROR_INVALID_USER_BUFFER)         continue;
        reportLastError();
      }
      if (device_interface_detail_data == null)       continue;
      char[] driverNameChars=new char[256];
      if (!SetupDiEnumDeviceInfo(device_info_set,deviceIndex,devinfo_data)) {
        reportLastError();
        continue;
      }
      if (!SetupDiGetDeviceRegistryProperty(device_info_set,devinfo_data,SPDRP_CLASS,null,driverNameChars,driverNameChars.length,null)) {
        reportLastError();
        continue;
      }
      int driverNameLen=0;
      while (driverNameChars[driverNameLen++] != 0)       ;
      String drivername=new String(driverNameChars,0,driverNameLen - 1);
      if ("String_Node_Str".equals(drivername)) {
        if (!SetupDiGetDeviceRegistryProperty(device_info_set,devinfo_data,SPDRP_DRIVER,null,driverNameChars,driverNameChars.length,null)) {
          if (GetLastError() != ERROR_INVALID_DATA)           reportLastError();
          continue;
        }
        char[] deviceIdChars=new char[256];
        int[] deviceIdLen={0};
        if (!SetupDiGetDeviceInstanceId(device_info_set,devinfo_data,deviceIdChars,deviceIdChars.length,deviceIdLen))         reportLastError();
        String deviceId=new String(deviceIdChars);
        int[] parent={devinfo_data.DevInst};
        while (CM_Get_Parent(parent,parent[0],0) == 0) {
          int[] parentIdLen={0};
          if (CM_Get_Device_ID_Size(parentIdLen,parent[0],0) != CR_SUCCESS)           reportLastError();
          parentIdLen[0]++;
          char[] parentIdChars=new char[parentIdLen[0]];
          if (CM_Get_Device_ID(parent[0],parentIdChars,parentIdLen[0],0) != CR_SUCCESS)           reportLastError();
          String parentId=new String(parentIdChars,0,parentIdLen[0] - 1);
          if (parentId.startsWith("String_Node_Str")) {
            deviceId=parentId;
            break;
          }
        }
        String path=new String(device_interface_detail_data.DevicePath);
        devHandle=openDeviceHandle(path,true);
        if (devHandle == INVALID_HANDLE_VALUE)         break;
        HIDD_ATTRIBUTES attrib=new HIDD_ATTRIBUTES();
        attrib.Size=new NativeLong(attrib.size());
        HidD_GetAttributes(devHandle,attrib);
        list.add(new HidDeviceInfo(path,deviceId,devHandle,attrib));
        CloseHandle(devHandle);
      }
    }
    SetupDiDestroyDeviceInfoList(device_info_set);
    return list;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}