Skip to content

Commit 88d08dc

Browse files
Use Unsafe.Slice instead of huge arrays to fix compilation issues on 32-bit systems
1 parent a3df3d1 commit 88d08dc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ncrypt.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,12 @@ func EnumProviders(
25482548
}()
25492549

25502550
if providersCount > 0 {
2551-
providerList := (*[1 << 30]ncryptProviderName)(unsafe.Pointer(providerListPtr))[:providersCount:providersCount]
2551+
count := int(providersCount)
2552+
if count < 0 {
2553+
err = fmt.Errorf("providersCount exceeds max int on this architecture")
2554+
return
2555+
}
2556+
providerList := unsafe.Slice((*ncryptProviderName)(unsafe.Pointer(providerListPtr)), count)
25522557
provsInfo = make([]NcryptProviderInfo, providersCount)
25532558
for i := range provsInfo {
25542559
provsInfo[i].fromInternal(providerList[i])
@@ -2786,7 +2791,12 @@ func (p *Provider) EnumAlgorithms(
27862791
}()
27872792

27882793
if algCount > 0 {
2789-
algList := (*[1 << 30]ncryptAlgorithmName)(unsafe.Pointer(algListPtr))[:algCount:algCount]
2794+
count := int(algCount)
2795+
if count < 0 {
2796+
err = fmt.Errorf("algCount exceeds max int on this architecture")
2797+
return
2798+
}
2799+
algList := unsafe.Slice((*ncryptAlgorithmName)(unsafe.Pointer(algListPtr)), count)
27902800
algsInfo = make([]NcryptAlgorithmInfo, algCount)
27912801
for i := range algsInfo {
27922802
algsInfo[i].fromInternal(algList[i])

0 commit comments

Comments
 (0)