diff mbox series

[Ada] Single character argument in call to Quote_Argument raises error

Message ID 20220704075018.GA99213@adacore.com
State New
Headers show
Series [Ada] Single character argument in call to Quote_Argument raises error | expand

Commit Message

Pierre-Marie de Rodat July 4, 2022, 7:50 a.m. UTC
This patch corrects an issue in the compiler whereby calling
Quote_Argument with an argument that is of size 1 may lead to a
CONSTRAINT_ERROR raised at runtime due to an undersized buffer.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* libgnat/s-os_lib.adb (Quote_Argument): Modify the result
	buffer size calculation to handle the case where Arg'Length is
	1.
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -1940,7 +1940,7 @@  package body System.OS_Lib is
       procedure Quote_Argument (Arg : in out String_Access) is
          J            : Positive := 1;
          Quote_Needed : Boolean  := False;
-         Res          : String (1 .. Arg'Length * 2);
+         Res          : String (1 .. Arg'Length * 2 + 2);
 
       begin
          if Arg (Arg'First) /= '"' or else Arg (Arg'Last) /= '"' then