jedisct1 / libsodium

A modern, portable, easy to use crypto library.
https://libsodium.org
Other
12.15k stars 1.73k forks source link

What is the difference between sodium_malloc and sodium_allocarray? #1037

Closed Chewhern closed 3 years ago

Chewhern commented 3 years ago

I am wondering what's the difference between sodium_malloc and sodium_allocarray?

Can anyone explains them in a simple explanation with easy to understand examples?

jedisct1 commented 3 years ago

Just copy/pasting the documentation:

The sodium_allocarray() function returns a pointer from which count objects that are size bytes of memory each can be accessed. It provides the same guarantees as sodium_malloc() but also protects against arithmetic overflows when count * size exceeds SIZE_MAX.