Ludovic Brenta | 9 Apr 2012 15:45

Debian Bug#666958: gnat-gps: GPS isn't looking in /usr/share/ada/adainclude for installed packages

While investigating http://bugs.debian.org/666958, I discovered a bug in
prj_editor/src/creation_wizard-dependencies.adb; the fix is:

--- a/prj_editor/src/creation_wizard-dependencies.adb
+++ b/prj_editor/src/creation_wizard-dependencies.adb
 <at>  <at>  -278,8 +278,9  <at>  <at> 
          --  Make sure the path isn't duplicated
          Found := False;

-         for K in Project_Path'Range loop
+         for K in Project_Path'First .. J - 1 loop
             if Project_Path (J) = Project_Path (K) then
+               --  We've already processed the same path before.  Abort.
                Found := True;
                exit;
             end if;

If you look in the sources, you will see that, without the patch, the
condition "Project_Path (J) = Project_Path (K)" is always true at least
once (i.e. when J = K) and therefore Found always becomes True and the
rest of the loop is never executed.  Also, there is a risk that a path
that appears twice (or more) in the Project_Path array is *never*
processed.  The patch carefully ensures that a duplicated path is
processed once.

--

-- 
Ludovic Brenta.
Emmanuel Briot | 10 Apr 2012 14:00
Favicon

Re: Debian Bug#666958: gnat-gps: GPS isn't looking in /usr/share/ada/adainclude for installed packages

> If you look in the sources, you will see that, without the patch, the
> condition "Project_Path (J) = Project_Path (K)" is always true at least
> once (i.e. when J = K) and therefore Found always becomes True and the
> rest of the loop is never executed.  Also, there is a risk that a path
> that appears twice (or more) in the Project_Path array is *never*
> processed.  The patch carefully ensures that a duplicated path is
> processed once.

Thanks.
I agree there is a bug there, although I chose a different approach than you 
patch (using a Set is more efficient than looping as we did before -- this was 
pre-Ada2005 code).

The following patch was applied, which I believe should work.

Emmanuel

--- a/prj_editor/src/creation_wizard-dependencies.adb
+++ b/prj_editor/src/creation_wizard-dependencies.adb
 <at>  <at>  -15,6 +15,7  <at>  <at> 
  -- of the license.                                                          --
  ------------------------------------------------------------------------------

+with Ada.Containers.Hashed_Sets;
  with Glib;                             use Glib;
  with Gtk.Box;                          use Gtk.Box;
  with Gtk.Button;                       use Gtk.Button;
 <at>  <at>  -58,6 +59,9  <at>  <at>  package body Creation_Wizard.Dependencies is
     package Wizard_Page_Handlers is new Gtk.Handlers.User_Callback
       (Gtk_Widget_Record, Project_Wizard_Page);
(Continue reading)

Ludovic Brenta | 10 Apr 2012 14:07

Re: Debian Bug#666958: gnat-gps: GPS isn't looking in /usr/share/ada/adainclude for installed packages

On Tue, 10 Apr 2012 14:00:53 +0200, Emmanuel Briot wrote:
> Thanks.
> I agree there is a bug there, although I chose a different approach
> than you patch (using a Set is more efficient than looping as we did
> before -- this was pre-Ada2005 code).

I don't think it really is more efficient in real cases where there are
two or three directories in Project_Path... but OK.  You could improve
the patch further by getting rid of the Found variable and directly
saying

   if not Visited.Contains (Project_Path (J)) then ...

--

-- 
Ludovic Brenta.

Gmane