From ce09c3c07f3bae669c0152ba4d72a708cfe27d0f Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Tue, 29 May 2018 09:39:11 +0000 Subject: [PATCH] [Ada] Fix constraint error in Normalize_Pathname Fix Normalize_Pathname to avoid a constraint error. 2018-05-29 Pascal Obry gcc/ada/ * libgnat/s-os_lib.adb (Normalize_Pathname): Fix handling of ".." in the root directory. gcc/testsuite/ * gnat.dg/normalize_pathname.adb: New testcase. From-SVN: r260872 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/libgnat/s-os_lib.adb | 18 ++++++++++++------ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/normalize_pathname.adb | 10 ++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/normalize_pathname.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 18a37dbf44a..6aea3c0b2a9 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-05-29 Pascal Obry + + * libgnat/s-os_lib.adb (Normalize_Pathname): Fix handling of ".." in + the root directory. + 2018-05-29 Pascal Obry * libgnat/s-os_lib.adb: Minor reformatting. diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb index 7e839cc687a..ca6eea18533 100644 --- a/gcc/ada/libgnat/s-os_lib.adb +++ b/gcc/ada/libgnat/s-os_lib.adb @@ -2389,12 +2389,18 @@ package body System.OS_Lib is elsif Finish = Start + 1 and then Path_Buffer (Start .. Finish) = ".." then - Start := Last; - loop - Start := Start - 1; - exit when Start = 1 - or else Path_Buffer (Start) = Directory_Separator; - end loop; + if Last > 1 then + Start := Last - 1; + + while Start > 1 + and then Path_Buffer (Start) /= Directory_Separator + loop + Start := Start - 1; + end loop; + + else + Start := Last; + end if; if Start = 1 then if Finish = End_Path then diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b5f0e1f6d67..947dfc28565 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-05-29 Pascal Obry + + * gnat.dg/normalize_pathname.adb: New testcase. + 2018-05-29 Tom de Vries * lib/scanasm.exp (scan-assembler-times): Use proc name in error diff --git a/gcc/testsuite/gnat.dg/normalize_pathname.adb b/gcc/testsuite/gnat.dg/normalize_pathname.adb new file mode 100644 index 00000000000..7d0bcb10429 --- /dev/null +++ b/gcc/testsuite/gnat.dg/normalize_pathname.adb @@ -0,0 +1,10 @@ +-- { dg-do run } + +with GNAT.OS_Lib; + +procedure Normalize_Pathname is + S : constant String := GNAT.OS_Lib.Normalize_Pathname + ("/../tmp", Directory => "", Resolve_Links => True); +begin + null; +end Normalize_Pathname; -- 2.30.2