Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: BlueHazzard on January 23, 2022, 09:55:14 pm

Title: Bug in AddMultipleFilesToProject
Post by: BlueHazzard 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?
Title: Re: Bug in AddMultipleFilesToProject
Post by: Miguel Gimenez 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);
Title: Re: Bug in AddMultipleFilesToProject
Post by: BlueHazzard on January 25, 2022, 10:15:34 am
fixed in trunk