summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2026-05-23 09:59:25 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2026-05-23 19:18:53 -0700
commit2e91ed5f129a4c03f7345d15d61232bd15028a4e (patch)
treec0e4eb4ba15603ba56762a3b23c77162284d5121 /src/alloc.c
parent82ad01b631a4ff4508bb3d37d32925d0cc6771ee (diff)
Prefer ptrdiff_t to size_t when either will do
Signed types are a bit safer, as they avoid some comparison confusion and -fsanitize=undefined can check more misuses of them. * src/alloc.c (lisp_malloc, lisp_align_malloc) (allocate_string_data, allocate_vector_from_block, object_bytes): * src/coding.c (from_unicode_buffer): * src/decompress.c (acc_size, accumulate_and_process_md5): * src/emacs.c (load_seccomp, shut_down_emacs): * src/fns.c (sxhash_bignum): * src/ftfont.c (get_adstyle_property): * src/image.c (lookup_image, xpm_init_color_cache) (xpm_cache_color): * src/json.c (json_out_str, struct json_parser) (json_make_object_workspace_for_slow_path) (json_make_object_workspace_for, json_parse_array) (json_parse_object): * src/sysdep.c (get_current_dir_name_or_unreachable) (init_sys_modes, convert_speed): * src/termchar.h (struct tty_display_info): * src/textconv.h (struct textconv_conversion_text): * src/xfns.c (struct x_xim_text_conversion_data) (x_encode_xim_text): * src/xselect.c (struct transfer, c_size_for_format) (x_size_for_format, selection_data_for_offset) (selection_data_size, x_start_selection_transfer) (x_continue_selection_transfer): Prefer ptrdiff_t to size_t when either will do. * src/term.c (Ftty__set_output_buffer_size): Limit output buffer size to PTRDIFF_MAX as well as to SIZE_MAX.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/alloc.c b/src/alloc.c
index d6f11d06766..ed0d6f4976d 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -899,7 +899,7 @@ void *lisp_malloc_loser EXTERNALLY_VISIBLE;
L == make_lisp_ptr (P, T), then XPNTR (L) == P and XTYPE (L) == T. */
static void *
-lisp_malloc (size_t nbytes, bool clearit, enum mem_type type)
+lisp_malloc (ptrdiff_t nbytes, bool clearit, enum mem_type type)
{
register void *val;
@@ -1083,7 +1083,7 @@ pointer_align (void *ptr, int alignment)
Alignment is on a multiple of BLOCK_ALIGN and `nbytes' has to be
smaller or equal to BLOCK_BYTES. */
static void *
-lisp_align_malloc (size_t nbytes, enum mem_type type)
+lisp_align_malloc (ptrdiff_t nbytes, enum mem_type type)
{
void *base, *val;
struct ablocks *abase;
@@ -1522,7 +1522,7 @@ sdata_size (ptrdiff_t n)
/* Exact bound on the number of bytes in a string, not counting the
terminating null. A string cannot contain more bytes than
- STRING_BYTES_BOUND, nor can it be so long that the size_t
+ STRING_BYTES_BOUND, nor can it be so long that the
arithmetic in allocate_string_data would overflow while it is
calculating a value to be passed to malloc. */
static ptrdiff_t const STRING_BYTES_MAX =
@@ -1768,7 +1768,7 @@ allocate_string_data (struct Lisp_String *s,
if (nbytes > LARGE_STRING_BYTES || immovable)
{
- size_t size = FLEXSIZEOF (struct sblock, data, needed);
+ ptrdiff_t size = FLEXSIZEOF (struct sblock, data, needed);
#ifdef DOUG_LEA_MALLOC
if (!mmap_lisp_allowed_p ())
@@ -2996,7 +2996,7 @@ allocate_vector_from_block (ptrdiff_t nbytes)
{
struct Lisp_Vector *vector;
struct vector_block *block;
- size_t index, restbytes;
+ ptrdiff_t index, restbytes;
eassume (VBLOCK_BYTES_MIN <= nbytes && nbytes <= VBLOCK_BYTES_MAX);
eassume (nbytes % roundup_size == 0);
@@ -3022,7 +3022,7 @@ allocate_vector_from_block (ptrdiff_t nbytes)
{
/* This vector is larger than requested. */
vector = vector_free_lists[index];
- size_t vector_nbytes = pseudovector_nbytes (&vector->header);
+ ptrdiff_t vector_nbytes = pseudovector_nbytes (&vector->header);
eassert (vector_nbytes > nbytes);
ASAN_UNPOISON_VECTOR_CONTENTS (vector, nbytes - header_size);
vector_free_lists[index] = next_vector (vector);
@@ -5465,10 +5465,10 @@ inhibit_garbage_collection (void)
}
/* Return the number of bytes in N objects each of size S, guarding
- against overflow if size_t is narrower than byte_ct. */
+ against overflow if ptrdiff_t is narrower than byte_ct. */
static byte_ct
-object_bytes (object_ct n, size_t s)
+object_bytes (object_ct n, ptrdiff_t s)
{
byte_ct b = s;
return n * b;