Author Topic: Bug in AddMultipleFilesToProject  (Read 3904 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Bug in AddMultipleFilesToProject
« on: January 23, 2022, 09:55:14 pm »
Code
int ProjectManager::AddMultipleFilesToProject(const wxArrayString& filelist, cbProject* project, int target)
{
    if (!project)
        project = GetActiveProject();

    wxArrayInt targets;
    targets.Add(target);
    if (AddMultipleFilesToProject(filelist, project, targets) == 1)
        return targets[0];
    return -1;
}

The documentation says, that in this function, if the parameter target == -1 then the user gets asked for the targets to add...
Now, AddMultipleFilesToProject calls DoAddFiles
Code
nt ProjectManager::DoAddFileToProject(const wxString& filename, cbProject* project, wxArrayInt& targets)
{
    if (!project)
        return 0;

    if (!SetupTargets(targets, project, m_ui))
        return 0;

And do add files calls setupTargets

Setup targets checks if the targets array is empty and if so, asks the user for the targets...
In our case the array is not empty, but filled with -1 so the documentation is wrong
Code
bool SetupTargets(wxArrayInt &targets, cbProject *project, cbProjectManagerUI *ui)
{
    cbAssert(project);
    cbAssert(ui);

    // do we have to ask for target?
    if (targets.GetCount() == 0)
    {

Or am i missing something?

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Bug in AddMultipleFilesToProject
« Reply #1 on: January 24, 2022, 09:19:37 am »
IMHO you are right, this
Code
    targets.Add(target);
should be changed to
Code
    if (target != -1)
        targets.Add(target);

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Bug in AddMultipleFilesToProject
« Reply #2 on: January 25, 2022, 10:15:34 am »
fixed in trunk