Project

General

Profile

Actions

Bug #18076

open

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

Added by xtkoba (Tee KOBAYASHI) 2 months ago. Updated 12 days ago.

Status:
Open
Priority:
Normal
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) 2 months 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) 12 days ago

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

Actions

Also available in: Atom PDF