mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
* Fixed parameter checking for make-string.
* Corrected a bug introduced with the last patch.
This commit is contained in:
parent
e382fdbe0f
commit
cb0d8be234
4 changed files with 55 additions and 20 deletions
|
@ -1,3 +1,16 @@
|
|||
2001-02-08 Dirk Herrmann <D.Herrmann@tu-bs.de>
|
||||
|
||||
* strings.h (SCM_STRING_MAX_LENGTH): New macro.
|
||||
|
||||
* strings.c (scm_makstr, scm_take_str, scm_make_string): Added
|
||||
range checking for the size parameter. Thanks to Martin
|
||||
Grabmueller for the hint.
|
||||
|
||||
(scm_makstr): Reordered string initialization to make interrupt
|
||||
deferring unnecessary.
|
||||
|
||||
* vectors.c (scm_make_vector): Fixed range checking.
|
||||
|
||||
2001-02-08 Dirk Herrmann <D.Herrmann@tu-bs.de>
|
||||
|
||||
* vectors.h (SCM_VECTOR_MAX_LENGTH): New macro.
|
||||
|
|
|
@ -124,19 +124,27 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
SCM
|
||||
scm_makstr (long len, int dummy)
|
||||
#define FUNC_NAME "scm_makstr"
|
||||
{
|
||||
SCM s;
|
||||
char *mem = (char *) scm_must_malloc (len + 1, "scm_makstr");
|
||||
char *mem;
|
||||
|
||||
SCM_ASSERT_RANGE (1, scm_long2num (len), len <= SCM_STRING_MAX_LENGTH);
|
||||
|
||||
mem = (char *) scm_must_malloc (len + 1, FUNC_NAME);
|
||||
mem[len] = 0;
|
||||
|
||||
SCM_NEWCELL (s);
|
||||
SCM_SET_STRING_CHARS (s, mem);
|
||||
SCM_SET_STRING_LENGTH (s, len);
|
||||
|
||||
return s;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
/* converts C scm_array of strings to SCM scm_list of strings. */
|
||||
/* If argc < 0, a null terminated scm_array is assumed. */
|
||||
|
@ -164,16 +172,21 @@ scm_makfromstrs (int argc, char **argv)
|
|||
made up. */
|
||||
SCM
|
||||
scm_take_str (char *s, int len)
|
||||
#define FUNC_NAME "scm_take_str"
|
||||
{
|
||||
SCM answer;
|
||||
|
||||
SCM_ASSERT_RANGE (2, scm_ulong2num (len), len <= SCM_STRING_MAX_LENGTH);
|
||||
|
||||
SCM_NEWCELL (answer);
|
||||
SCM_DEFER_INTS;
|
||||
SCM_SET_STRING_CHARS (answer, s);
|
||||
SCM_SET_STRING_LENGTH (answer, len);
|
||||
scm_done_malloc (len + 1);
|
||||
SCM_SET_STRING_CHARS (answer, s);
|
||||
SCM_ALLOW_INTS;
|
||||
|
||||
return answer;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
/* `s' must be a malloc'd string. See scm_take_str. */
|
||||
SCM
|
||||
|
@ -208,8 +221,6 @@ scm_makfrom0str_opt (const char *src)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SCM_DEFINE (scm_make_string, "make-string", 1, 1, 0,
|
||||
(SCM k, SCM chr),
|
||||
"Returns a newly allocated string of\n"
|
||||
|
@ -218,24 +229,34 @@ SCM_DEFINE (scm_make_string, "make-string", 1, 1, 0,
|
|||
"STRING are unspecified.\n")
|
||||
#define FUNC_NAME s_scm_make_string
|
||||
{
|
||||
SCM res;
|
||||
register long i;
|
||||
SCM_VALIDATE_INUM_MIN_COPY (1,k,0,i);
|
||||
res = scm_makstr (i, 0);
|
||||
if (!SCM_UNBNDP (chr))
|
||||
if (SCM_INUMP (k))
|
||||
{
|
||||
SCM_VALIDATE_CHAR (2,chr);
|
||||
{
|
||||
unsigned char *dst = SCM_STRING_UCHARS (res);
|
||||
char c = SCM_CHAR (chr);
|
||||
|
||||
memset (dst, c, i);
|
||||
}
|
||||
long int i = SCM_INUM (k);
|
||||
SCM res;
|
||||
|
||||
SCM_ASSERT_RANGE (1, k, i >= 0);
|
||||
|
||||
res = scm_makstr (i, 0);
|
||||
if (!SCM_UNBNDP (chr))
|
||||
{
|
||||
unsigned char *dst;
|
||||
|
||||
SCM_VALIDATE_CHAR (2, chr);
|
||||
|
||||
dst = SCM_STRING_UCHARS (res);
|
||||
memset (dst, SCM_CHAR (chr), i);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
else if (SCM_BIGP (k))
|
||||
SCM_OUT_OF_RANGE (1, k);
|
||||
else
|
||||
SCM_WRONG_TYPE_ARG (1, k);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
SCM_DEFINE (scm_string_length, "string-length", 1, 0, 0,
|
||||
(SCM string),
|
||||
"Returns the number of characters in STRING")
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
#define SCM_STRING_CHARS(x) ((char *) (SCM_CELL_WORD_1 (x)))
|
||||
#endif
|
||||
#define SCM_SET_STRING_CHARS(s, c) (SCM_SET_CELL_WORD_1 ((s), (c)))
|
||||
#define SCM_STRING_MAX_LENGTH ((1L << 24) - 1)
|
||||
#define SCM_STRING_LENGTH(x) (((unsigned long) SCM_CELL_WORD_0 (x)) >> 8)
|
||||
#define SCM_SET_STRING_LENGTH(s, l) (SCM_SET_CELL_WORD_0 ((s), ((l) << 8) + scm_tc7_string))
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ SCM_DEFINE (scm_make_vector, "make-vector", 1, 1, 0,
|
|||
|
||||
if (SCM_INUMP (k))
|
||||
{
|
||||
SCM_ASSERT_RANGE (1, k, k >= 0);
|
||||
SCM_ASSERT_RANGE (1, k, SCM_INUM (k) >= 0);
|
||||
return scm_c_make_vector (SCM_INUM (k), fill);
|
||||
}
|
||||
else if (SCM_BIGP (k))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue