aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2018-07-16 14:10:58 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-07-16 14:10:58 +0000
commit3c820aca5548d850811e41f7aa85f4a7fb10d6ed (patch)
treef5a98a5b17dc2d48840fb981d2493311ba019685 /gcc/ada
parent2588c36c2ea1f62176b07268fa7a8e0cedeb4fbf (diff)
downloadgcc-3c820aca5548d850811e41f7aa85f4a7fb10d6ed.zip
gcc-3c820aca5548d850811e41f7aa85f4a7fb10d6ed.tar.gz
gcc-3c820aca5548d850811e41f7aa85f4a7fb10d6ed.tar.bz2
[Ada] Segmentation_Fault with Integer'Wide_Wide_Value
This patch updates the routines which produce Wide_String and Wide_Wide_String from a String to construct a result of the proper maximum size which is later sliced. 2018-07-16 Hristian Kirtchev <kirtchev@adacore.com> gcc/ada/ * libgnat/s-wchwts.adb (Wide_String_To_String): Use the appropriate longest sequence factor. Code clean up. (Wide_Wide_String_To_String): Use the appropriate longest sequence factor. Code clean up. gcc/testsuite/ * gnat.dg/wide_wide_value1.adb: New testcase. From-SVN: r262713
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/libgnat/s-wchwts.adb39
2 files changed, 33 insertions, 13 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 51b73f8..a782582 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-16 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * libgnat/s-wchwts.adb (Wide_String_To_String): Use the appropriate
+ longest sequence factor. Code clean up.
+ (Wide_Wide_String_To_String): Use the appropriate longest sequence
+ factor. Code clean up.
+
2018-07-16 Javier Miranda <miranda@adacore.com>
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Report an error
diff --git a/gcc/ada/libgnat/s-wchwts.adb b/gcc/ada/libgnat/s-wchwts.adb
index c5556ab..4eed382 100644
--- a/gcc/ada/libgnat/s-wchwts.adb
+++ b/gcc/ada/libgnat/s-wchwts.adb
@@ -86,16 +86,23 @@ package body System.WCh_WtS is
(S : Wide_String;
EM : WC_Encoding_Method) return String
is
- R : String (S'First .. S'First + 5 * S'Length); -- worst case length
- RP : Natural;
+ Max_Chars : constant Natural := WC_Longest_Sequences (EM);
+
+ Result : String (S'First .. S'First + Max_Chars * S'Length);
+ Result_Idx : Natural;
begin
- RP := R'First - 1;
- for SP in S'Range loop
- Store_UTF_32_Character (Wide_Character'Pos (S (SP)), R, RP, EM);
+ Result_Idx := Result'First - 1;
+
+ for S_Idx in S'Range loop
+ Store_UTF_32_Character
+ (U => Wide_Character'Pos (S (S_Idx)),
+ S => Result,
+ P => Result_Idx,
+ EM => EM);
end loop;
- return R (R'First .. RP);
+ return Result (Result'First .. Result_Idx);
end Wide_String_To_String;
--------------------------------
@@ -106,17 +113,23 @@ package body System.WCh_WtS is
(S : Wide_Wide_String;
EM : WC_Encoding_Method) return String
is
- R : String (S'First .. S'First + 7 * S'Length); -- worst case length
- RP : Natural;
+ Max_Chars : constant Natural := WC_Longest_Sequences (EM);
- begin
- RP := R'First - 1;
+ Result : String (S'First .. S'First + Max_Chars * S'Length);
+ Result_Idx : Natural;
- for SP in S'Range loop
- Store_UTF_32_Character (Wide_Wide_Character'Pos (S (SP)), R, RP, EM);
+ begin
+ Result_Idx := Result'First - 1;
+
+ for S_Idx in S'Range loop
+ Store_UTF_32_Character
+ (U => Wide_Wide_Character'Pos (S (S_Idx)),
+ S => Result,
+ P => Result_Idx,
+ EM => EM);
end loop;
- return R (R'First .. RP);
+ return Result (Result'First .. Result_Idx);
end Wide_Wide_String_To_String;
end System.WCh_WtS;