aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Dewar <dewar@adacore.com>2007-06-06 12:41:57 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2007-06-06 12:41:57 +0200
commit0e701488e1f731a529f6b391e538d369777c32c0 (patch)
tree4d72d1588d56d4b9ac42f309727482c33856aa1b
parentb06f1f839cd54e81ff74be32d30aa702d7b18917 (diff)
downloadgcc-0e701488e1f731a529f6b391e538d369777c32c0.zip
gcc-0e701488e1f731a529f6b391e538d369777c32c0.tar.gz
gcc-0e701488e1f731a529f6b391e538d369777c32c0.tar.bz2
scng.adb: (Check_End_Of_Line): Deal with very long lines
2007-04-20 Robert Dewar <dewar@adacore.com> * scng.adb: (Check_End_Of_Line): Deal with very long lines From-SVN: r125445
-rw-r--r--gcc/ada/scng.adb53
1 files changed, 50 insertions, 3 deletions
diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb
index c4fdd86..e9a0e02 100644
--- a/gcc/ada/scng.adb
+++ b/gcc/ada/scng.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -39,10 +39,9 @@ with Urealp; use Urealp;
with Widechar; use Widechar;
with System.CRC32;
+with System.UTF_32; use System.UTF_32;
with System.WCh_Con; use System.WCh_Con;
-with GNAT.UTF_32; use GNAT.UTF_32;
-
package body Scng is
use ASCII;
@@ -267,6 +266,46 @@ package body Scng is
Error_Long_Line;
end if;
+ -- Now one more checking circuit. Normally we are only enforcing a
+ -- limit of physical characters, with tabs counting as one character.
+ -- But if after tab expansion we would have a total line length that
+ -- exceeded 32766, that would really cause trouble, because column
+ -- positions would exceed the maximum we allow for a column count.
+ -- Note: the limit is 32766 rather than 32767, since we use a value
+ -- of 32767 for special purposes (see Sinput). Now we really do not
+ -- want to go messing with tabs in the normal case, so what we do is
+ -- to check for a line that has more than 4096 physical characters.
+ -- Any shorter line could not be a problem, even if it was all tabs.
+
+ if Len >= 4096 then
+ declare
+ Col : Natural;
+ Ptr : Source_Ptr;
+
+ begin
+ Col := 1;
+ Ptr := Current_Line_Start;
+ loop
+ exit when Ptr = Scan_Ptr;
+
+ if Source (Ptr) = ASCII.HT then
+ Col := (Col - 1 + 8) / 8 * 8 + 1;
+ else
+ Col := Col + 1;
+ end if;
+
+ if Col > 32766 then
+ Error_Msg
+ ("this line is longer than 32766 characters",
+ Current_Line_Start);
+ raise Unrecoverable_Error;
+ end if;
+
+ Ptr := Ptr + 1;
+ end loop;
+ end;
+ end if;
+
-- Reset wide character byte count for next line
Wide_Char_Byte_Count := 0;
@@ -2441,6 +2480,14 @@ package body Scng is
end loop Tabs_Loop;
return Start_Column;
+
+ -- A constraint error can happen only if we have a compiler with checks on
+ -- and a line with a ludicrous number of tabs or spaces at the start. In
+ -- such a case, we really don't care if Start_Column is right or not.
+
+ exception
+ when Constraint_Error =>
+ return Start_Column;
end Set_Start_Column;
end Scng;