diff options
author | Tristan Gingold <tgingold@free.fr> | 2017-03-06 07:56:46 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2017-03-09 20:42:56 +0100 |
commit | 9a191a62fe59eadc2051daaab7a85215346c9200 (patch) | |
tree | 72075361f62edc3b4d21af5e19dea02a86230abc /src/files_map.adb | |
parent | e98e46d3ced2ac81796ef3b19c88eea35b659516 (diff) | |
download | ghdl-9a191a62fe59eadc2051daaab7a85215346c9200.tar.gz ghdl-9a191a62fe59eadc2051daaab7a85215346c9200.tar.bz2 ghdl-9a191a62fe59eadc2051daaab7a85215346c9200.zip |
Do not crash on empty file.
Fix #309
Diffstat (limited to 'src/files_map.adb')
-rw-r--r-- | src/files_map.adb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/files_map.adb b/src/files_map.adb index 4d75a35d2..3cb7e0594 100644 --- a/src/files_map.adb +++ b/src/files_map.adb @@ -796,15 +796,21 @@ package body Files_Map is -- Load_Source_File call must follow its Create_Source_File. pragma Assert (Source_Files.Table (Res).First_Location = Next_Location); + -- Compute the SHA1. declare use GNAT.SHA1; use Str_Table; subtype Buffer_String is String (1 .. Buffer'Length - 2); - Buffer_Digest : constant Message_Digest := - Digest (Buffer_String - (Buffer (Source_Ptr_Org .. Source_Ptr_Org + Length - 1))); + Buffer_Digest : Message_Digest; begin + if Length /= 0 then + -- Avoid weird bounds for empty buffers. + Buffer_Digest := Digest + (Buffer_String + (Buffer (Source_Ptr_Org .. Source_Ptr_Org + Length - 1))); + end if; + Source_Files.Table (Res).Checksum := File_Checksum_Id (Create_String8); for I in Buffer_Digest'Range loop |