From c99862ee5347d82a68a68bcd7048fb246d90aabf Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 15 Jul 2016 08:58:26 -0400 Subject: [PATCH] check: creator.curSet pointer aliasing When iterating over creator.DH.Entries using the variable e, and then setting creator.curSet to &e, this causes aliasing that results in the underlying Entry of creator.curSet to change on each iteration. Instead we want to get the address of the actual Entry in creator.DH.Entries. Signed-off-by: Stephen Chung --- check.go | 4 ++-- check_test.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/check.go b/check.go index 9651cb3..d27b50f 100644 --- a/check.go +++ b/check.go @@ -41,11 +41,11 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err sort.Sort(byPos(creator.DH.Entries)) var result Result - for _, e := range creator.DH.Entries { + for i, e := range creator.DH.Entries { switch e.Type { case SpecialType: if e.Name == "/set" { - creator.curSet = &e + creator.curSet = &creator.DH.Entries[i] } else if e.Name == "/unset" { creator.curSet = nil } diff --git a/check_test.go b/check_test.go index bd757ef..17ba47a 100644 --- a/check_test.go +++ b/check_test.go @@ -108,7 +108,7 @@ func TestTimeComparison(t *testing.T) { // This is the format of time from FreeBSD spec := ` /set type=file time=5.000000000 -. type=dir +. type=dir file time=5.000000000 .. ` @@ -122,6 +122,9 @@ func TestTimeComparison(t *testing.T) { if err := os.Chtimes(fh.Name(), epoch, epoch); err != nil { t.Fatal(err) } + if err := os.Chtimes(dir, epoch, epoch); err != nil { + t.Fatal(err) + } if err := fh.Close(); err != nil { t.Error(err) }