Fix instances of -Wnull-pointer-arithmetic
As of https://reviews.llvm.org/D98798, clang warns on UB from
subtraction against a null pointer. This addresses one of the new
instances of this warning.
Bug: 75276
Change-Id: Iebd43796deae1dccc18ababcff1e75769b518cfb
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/libpng/+/529201
Reviewed-by: Shai Barack <shayba@google.com>
diff --git a/pngpriv.h b/pngpriv.h
index 6162be5..8e54442 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -540,7 +540,7 @@
/* This implicitly assumes alignment is always to a power of 2. */
#ifdef png_alignof
# define png_isaligned(ptr, type)\
- ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)
+ ((((uintptr_t)ptr) & (png_alignof(type)-1)) == 0)
#else
# define png_isaligned(ptr, type) 0
#endif
diff --git a/pngrutil.c b/pngrutil.c
index 1c8a179..a1d92fe 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -4471,11 +4471,11 @@
*/
{
png_bytep temp = png_ptr->big_row_buf + 32;
- int extra = (int)((temp - (png_bytep)0) & 0x0f);
+ int extra = (int)(((uintptr_t)temp) & 0x0f);
png_ptr->row_buf = temp - extra - 1/*filter byte*/;
temp = png_ptr->big_prev_row + 32;
- extra = (int)((temp - (png_bytep)0) & 0x0f);
+ extra = (int)(((uintptr_t)temp) & 0x0f);
png_ptr->prev_row = temp - extra - 1/*filter byte*/;
}