mirror of
https://github.com/pgsty/minio.git
synced 2026-03-16 17:53:43 +01:00
Safely use unsafe.Pointer to avoid crashes on ARM (#8027)
Refactor the Dirent parsing code such that when we calculate offsets are correct based on the platform This PR fixes a silent potential crash on ARM architecture.
This commit is contained in:
@@ -223,7 +223,7 @@ func TestReadDirN(t *testing.T) {
|
||||
}{
|
||||
{0, 0, 0},
|
||||
{0, 1, 0},
|
||||
{1, 0, 1},
|
||||
{1, 0, 0},
|
||||
{0, -1, 0},
|
||||
{1, -1, 1},
|
||||
{10, -1, 10},
|
||||
@@ -236,19 +236,24 @@ func TestReadDirN(t *testing.T) {
|
||||
|
||||
for i, testCase := range testCases {
|
||||
dir := mustSetupDir(t)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
for c := 1; c <= testCase.numFiles; c++ {
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%d", c)), []byte{}, os.ModePerm); err != nil {
|
||||
err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%d", c)), []byte{}, os.ModePerm)
|
||||
if err != nil {
|
||||
os.RemoveAll(dir)
|
||||
t.Fatalf("Unable to create a file, %s", err)
|
||||
}
|
||||
}
|
||||
entries, err := readDirN(dir, testCase.n)
|
||||
if err != nil {
|
||||
os.RemoveAll(dir)
|
||||
t.Fatalf("Unable to read entries, %s", err)
|
||||
}
|
||||
if len(entries) != testCase.expectedNum {
|
||||
t.Fatalf("Test %d: unexpected number of entries, waiting for %d, but found %d", i+1, testCase.expectedNum, len(entries))
|
||||
os.RemoveAll(dir)
|
||||
t.Fatalf("Test %d: unexpected number of entries, waiting for %d, but found %d",
|
||||
i+1, testCase.expectedNum, len(entries))
|
||||
}
|
||||
os.RemoveAll(dir)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user