1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-23 13:00:34 +02:00

* gh_data.c (gh_set_substr): Add casts to avoid signed/unsigned

comparisons, and range checking to make sure those casts are
harmless.
This commit is contained in:
Jim Blandy 1998-09-06 18:15:19 +00:00
parent 2d2c87e1e1
commit fd88bd7cc2

View file

@ -102,16 +102,20 @@ void
gh_set_substr (char *src, SCM dst, int start, int len) gh_set_substr (char *src, SCM dst, int start, int len)
{ {
char *dst_ptr; char *dst_ptr;
unsigned long dst_len, effective_length; unsigned long dst_len;
unsigned long effective_length;
SCM_ASSERT (SCM_NIMP (dst) && SCM_STRINGP (dst), dst, SCM_ARG3, SCM_ASSERT (SCM_NIMP (dst) && SCM_STRINGP (dst), dst, SCM_ARG3,
"gh_set_substr"); "gh_set_substr");
scm_protect_object (dst);
dst_ptr = SCM_CHARS (dst); dst_ptr = SCM_CHARS (dst);
dst_len = SCM_LENGTH (dst); dst_len = SCM_LENGTH (dst);
effective_length = (len < dst_len) ? len : dst_len; SCM_ASSERT (len >= 0 && (unsigned) len <= dst_len,
memcpy (dst_ptr + start, src, effective_length); dst, SCM_ARG4, "gh_set_substr");
/* FIXME: must signal an error if len > dst_len */
scm_protect_object (dst);
effective_length = ((unsigned) len < dst_len) ? len : dst_len;
memmove (dst_ptr + start, src, effective_length);
scm_unprotect_object (dst); scm_unprotect_object (dst);
} }