]> granicus.if.org Git - php/commitdiff
FFI: Use signed arithmetic for pointer offset
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Jun 2019 12:52:12 +0000 (14:52 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Jun 2019 14:22:26 +0000 (16:22 +0200)
offset can be negative here, using signed arithmetic avoids ubsan
warnings.

ext/ffi/ffi.c

index 1b016c00a606ded3e9b0aed07be1acc82b9a743d..20a215a42aa328fcd849fa8b9339add67c46a970 100644 (file)
@@ -1638,7 +1638,7 @@ static zend_object* zend_ffi_add(zend_ffi_cdata *base_cdata, zend_ffi_type *base
        }
        cdata->ptr = &cdata->ptr_holder;
        cdata->ptr_holder = ptr +
-               offset * ZEND_FFI_TYPE(ptr_type)->size;
+               (ptrdiff_t) (offset * ZEND_FFI_TYPE(ptr_type)->size);
        cdata->flags = base_cdata->flags & ZEND_FFI_FLAG_CONST;
        return &cdata->std;
 }