jedisct1 / libsodium-doc

Gitbook documentation for libsodium
https://libsodium.org
ISC License
166 stars 159 forks source link

Add note on `sodium_malloc` return value #49

Closed emilbayes closed 6 years ago

emilbayes commented 6 years ago

I found this by reading the source, however I'm not sure errno is always set. Following this code path, it seems that NULL may be returned, but errno is not set:

https://github.com/jedisct1/libsodium/blob/69642f040935d9458ea3d2ba83696751c24bc13a/src/libsodium/sodium/utils.c#L538-L540

jedisct1 commented 6 years ago

Hi Emil,

_alloc_aligned() will set errno.

jedisct1 commented 6 years ago

Merged, thanks a lot!

emilbayes commented 6 years ago

Ah ok! Still learning! I should have followed the code down mmap, posix_memalign and VirtualAlloc. Good stuff to study :)

emilbayes commented 6 years ago

@jedisct1 Reading about VirtualAlloc, should we check GetLastError in sodium-native on Windows like we check errno on UNIX?

jedisct1 commented 6 years ago

Mmmm... I don't know if VirtualAlloc() also sets errno or not. Might be worth checking. If it doesn't, maybe libsodium should set errno, so that in applications, there's only one thing to check no matter what the platform is.

emilbayes commented 6 years ago

@jedisct1 The documentation doesn't indicate that it does, but I can't test it myself atm: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx

jedisct1 commented 6 years ago

I don't have access to a Windows VM right now, so if you could test, that would be very useful!

emilbayes commented 6 years ago

Ah missing t. I will try to remember to check next time I have access to a windows machine