Skip to content

Commit

Permalink
Use NULL instead of 0 for null pointers
Browse files Browse the repository at this point in the history
Turns out the standard guarantees that NULL is defined in `stddef.h`.
Contrary to what I used to believe, using it doesn't induce any further
dependency.  `0` is also guaranteed by the standard to work, but it's
less explicit and in some cases more error prone.
  • Loading branch information
LoupVaillant committed Oct 17, 2023
1 parent 7c83137 commit 9a2c0d4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/monocypher.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ u64 crypto_chacha20_djb(u8 *cipher_text, const u8 *plain_text,
size_t nb_blocks = text_size >> 6;
FOR (i, 0, nb_blocks) {
chacha20_rounds(pool, input);
if (plain_text != 0) {
if (plain_text != NULL) {
FOR (j, 0, 16) {
u32 p = pool[j] + input[j];
store32_le(cipher_text, p ^ load32_le(plain_text));
Expand All @@ -255,7 +255,7 @@ u64 crypto_chacha20_djb(u8 *cipher_text, const u8 *plain_text,

// Last (incomplete) block
if (text_size > 0) {
if (plain_text == 0) {
if (plain_text == NULL) {
plain_text = zero;
}
chacha20_rounds(pool, input);
Expand Down

0 comments on commit 9a2c0d4

Please sign in to comment.