From 861ed5debba4c586f98b08ef520dbec534bd08b9 Mon Sep 17 00:00:00 2001 From: Wondertan Date: Wed, 28 Sep 2022 12:30:42 +0200 Subject: [PATCH 1/2] fix: check for nil before setting nil --- datasquare.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/datasquare.go b/datasquare.go index 45393fa..0ca2656 100644 --- a/datasquare.go +++ b/datasquare.go @@ -176,8 +176,12 @@ func (ds *dataSquare) setColSlice(x uint, y uint, newCol [][]byte) error { } func (ds *dataSquare) resetRoots() { - ds.rowRoots = nil - ds.colRoots = nil + if ds.rowRoots != nil { + ds.rowRoots = nil + } + if ds.colRoots != nil { + ds.colRoots = nil + } } func (ds *dataSquare) computeRoots() { From ed5b81ebc9a0262ea08834a50ef05501bc8b74fc Mon Sep 17 00:00:00 2001 From: Wondertan Date: Wed, 28 Sep 2022 16:29:28 +0200 Subject: [PATCH 2/2] docs: comment on why nil checks are needed --- datasquare.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/datasquare.go b/datasquare.go index 0ca2656..991a18e 100644 --- a/datasquare.go +++ b/datasquare.go @@ -176,6 +176,9 @@ func (ds *dataSquare) setColSlice(x uint, y uint, newCol [][]byte) error { } func (ds *dataSquare) resetRoots() { + // don't write nil if it's already nil + // this prevents rewriting nil into shared memory slot + // when resetRoots is used from multiple routines if ds.rowRoots != nil { ds.rowRoots = nil }