Skip to content

Commit

Permalink
Fix: potential undefined behaviour when subtracting null pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
rubidium42 committed May 3, 2024
1 parent 4fb09f2 commit 0e4e7d4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/md5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "md5.h"
#include <string.h>
#include <cstdint>

#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#ifdef ARCH_IS_BIG_ENDIAN
Expand Down Expand Up @@ -161,7 +162,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - (const md5_byte_t *)0) & 3)) {
if (reinterpret_cast<std::uintptr_t>(data) & 3) {
/* data are properly aligned */
X = (const md5_word_t *)data;
} else {
Expand Down

0 comments on commit 0e4e7d4

Please sign in to comment.