Skip to content

Commit

Permalink
Merge branch 'mr/lambourg/91-file-indexes-valgrind' into 'master'
Browse files Browse the repository at this point in the history
File_Indexes: fix uninitialized digest upon error

Closes #91

See merge request eng/toolchain/gnatcoll-core!149
  • Loading branch information
Nikokrock committed Oct 28, 2024
2 parents b647dd7 + 4dcc165 commit 6a137f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/gnatcoll-file_indexes.adb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ package body GNATCOLL.File_Indexes is
use type Stat.File_Attributes;
use type Ada.Calendar.Time;

No_Digest : constant File_Index_Digest := (others => ' ');
Prev_Cursor : Cursor := Find (Self.DB, Normalized_Path);
Prev_Hash : File_Index_Digest;
New_Hash : File_Index_Digest;
Prev_Hash : File_Index_Digest := No_Digest;
New_Hash : File_Index_Digest := No_Digest;
Trust_New_Hash : Boolean := True;
begin

Expand All @@ -128,7 +129,8 @@ package body GNATCOLL.File_Indexes is

if not Stat.Exists (Attrs) then
Delete (Self.DB, Prev_Cursor);
State := REMOVED_FILE;
State := REMOVED_FILE;
Digest := No_Digest;
return;
end if;

Expand All @@ -149,9 +151,11 @@ package body GNATCOLL.File_Indexes is
(Blake3.Blake3_File_Hash (Path => Normalized_Path));
exception
when others =>
State := UNHASHABLE_FILE;
State := UNHASHABLE_FILE;
Digest := No_Digest;
return;
end;

-- Some file system do not have a better resolution than 1s for
-- modification time. If at the time of the query the file has been
-- modified less than 1s ago, there is a possible race condition in
Expand Down
4 changes: 4 additions & 0 deletions core/src/hash/blake3/gnatcoll-hash-blake3.adb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ package body GNATCOLL.Hash.Blake3 is
FS.Close (FD);
Free (Buffer);
return Context.Hash_Digest;
exception
when others =>
Free (Buffer);
raise;
end Blake3_File_Hash;

-----------------
Expand Down

0 comments on commit 6a137f7

Please sign in to comment.