Project

General

Profile

Actions

Bug #18076

closed

ext/digest/md5/md5.c: `-Wnull-pointer-subtraction` warning by Clang 13

Added by xtkoba (Tee KOBAYASHI) almost 3 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-08-16T00:07:09Z master 4cc44bd819) [x86_64-linux]
[ruby-core:104925]

Description

compiling ../../../../ext/digest/md5/md5.c
../../../../ext/digest/md5/md5.c:228:17: warning: performing pointer subtraction with a null pointer has undefined behavior [-Wnull-pointer-subtraction]
    if (!((data - (const uint8_t *)0) & 3)) {
                ^ ~~~~~~~~~~~~~~~~~~
1 warning generated.

Updated by xtkoba (Tee KOBAYASHI) almost 3 years ago

Proposed patch:

--- a/ext/digest/md5/md5.c
+++ b/ext/digest/md5/md5.c
@@ -225,7 +225,7 @@
     uint32_t xbuf[16];
     const uint32_t *X;
 
-    if (!((data - (const uint8_t *)0) & 3)) {
+    if (!(((uintptr_t)data) & 3)) {
 	/* data are properly aligned */
 	X = (const uint32_t *)data;
     } else {

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

I submitted a pull request upstream to fix this: https://github.com/ruby/digest/pull/29

Actions #3

Updated by xtkoba (Tee KOBAYASHI) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|fed65e6a48c5bed938c9bafb40409cd7e398f1c9.


[ruby/digest] Avoid null pointer subtraction in digest/md5

Fixes warning on Clang 13.

Fixes [Bug #18076]

https://github.com/ruby/digest/commit/32135c7487

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0