mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-01 23:30:40 -08:00
Introduce function coerce_to_simple_string() to ensure that C functions get a null-terminated string
This commit is contained in:
parent
b55a0130bc
commit
da477db1ea
4 changed files with 21 additions and 8 deletions
|
|
@ -251,7 +251,8 @@ open_stream(cl_object fn, enum smmode smm, cl_object if_exists,
|
|||
{
|
||||
cl_object x;
|
||||
FILE *fp;
|
||||
char *fname = coerce_to_filename(fn)->string.self;
|
||||
cl_object filename = coerce_to_filename(fn);
|
||||
char *fname = filename->string.self;
|
||||
|
||||
if (smm == smm_input || smm == smm_probe) {
|
||||
fp = fopen(fname, OPEN_R);
|
||||
|
|
|
|||
|
|
@ -116,6 +116,13 @@ copy_simple_string(cl_object x)
|
|||
return(y);
|
||||
}
|
||||
|
||||
cl_object
|
||||
coerce_to_simple_string(cl_object x)
|
||||
{
|
||||
assert_type_string(x);
|
||||
return x->string.adjustable? copy_simple_string(x) : x;
|
||||
}
|
||||
|
||||
cl_object
|
||||
cl_string(cl_object x)
|
||||
{
|
||||
|
|
@ -220,7 +227,7 @@ string_eq(cl_object x, cl_object y)
|
|||
cl_index i, j;
|
||||
i = x->string.fillp;
|
||||
j = y->string.fillp;
|
||||
return (i == j && strncmp(x->string.self, y->string.self, i) == 0);
|
||||
return (i == j && memcmp(x->string.self, y->string.self, i) == 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -239,8 +239,11 @@ si_open_client_stream(cl_object host, cl_object port)
|
|||
int fd, p; /* file descriptor */
|
||||
cl_object streamIn, streamOut;
|
||||
|
||||
assert_type_string(host); /* Ensure "host" is a string */
|
||||
p = fixnnint(port); /* INV: fixnnint() checks type */
|
||||
/* Ensure "host" is a string that we can pass to a C function */
|
||||
host = coerce_to_simple_string(host);
|
||||
|
||||
/* The port number is not negative */
|
||||
p = fixnnint(port);
|
||||
|
||||
if (host->string.fillp > BUFSIZ - 1)
|
||||
FEerror("~S is a too long file name.", 1, host);
|
||||
|
|
@ -334,7 +337,7 @@ si_lookup_host_entry(cl_object host_or_address)
|
|||
|
||||
switch (type_of(host_or_address)) {
|
||||
case t_string:
|
||||
host_or_address->string.self[host_or_address->string.fillp] = 0;
|
||||
host_or_address = coerce_to_simple_string(host_or_address);
|
||||
he = gethostbyname(host_or_address->string.self);
|
||||
break;
|
||||
case t_fixnum:
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ truedirectory(cl_object pathname)
|
|||
if (chdir("..") < 0)
|
||||
return error_no_dir(pathname);
|
||||
} else if (type_of(name) == t_string) {
|
||||
name = coerce_to_simple_string(name);
|
||||
if (chdir(name->string.self) < 0)
|
||||
return error_no_dir(pathname);
|
||||
} else
|
||||
|
|
@ -280,7 +281,6 @@ cl_delete_file(cl_object file)
|
|||
{
|
||||
cl_object filename;
|
||||
|
||||
/* INV: coerce_to_filename() checks types */
|
||||
filename = coerce_to_filename(file);
|
||||
if (unlink(filename->string.self) < 0)
|
||||
FEfilesystem_error("Cannot delete the file ~S.", 1, file);
|
||||
|
|
@ -307,7 +307,6 @@ cl_file_write_date(cl_object file)
|
|||
cl_object filename, time;
|
||||
struct stat filestatus;
|
||||
|
||||
/* INV: coerce_to_filename() checks types */
|
||||
filename = coerce_to_filename(file);
|
||||
if (stat(filename->string.self, &filestatus) < 0)
|
||||
time = Cnil;
|
||||
|
|
@ -326,7 +325,6 @@ cl_file_author(cl_object file)
|
|||
extern struct passwd *getpwuid(uid_t);
|
||||
#endif
|
||||
|
||||
/* INV: coerce_to_filename() checks types */
|
||||
filename = coerce_to_filename(file);
|
||||
if (stat(filename->string.self, &filestatus) < 0)
|
||||
FEfilesystem_error("Cannot get the file status of ~S.", 1,
|
||||
|
|
@ -492,6 +490,8 @@ actual_directory(cl_object namestring, cl_object mask, bool all)
|
|||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
namestring = coerce_to_simple_string(namestring);
|
||||
mask = coerce_to_simple_string(mask);
|
||||
if (chdir(namestring->string.self) < 0) {
|
||||
chdir(saved_dir->string.self);
|
||||
FEfilesystem_error("directory: cannot access ~A", 1, namestring);
|
||||
|
|
@ -521,6 +521,8 @@ actual_directory(cl_object namestring, cl_object mask, bool all)
|
|||
char iobuffer[BUFSIZ];
|
||||
DIRECTORY dir;
|
||||
|
||||
namestring = coerce_to_simple_string(namestring);
|
||||
mask = coerce_to_simple_string(mask);
|
||||
if (chdir(namestring->string.self) < 0) {
|
||||
chdir(saved_dir->string.self);
|
||||
FEfilesystem_error("directory: cannot access ~A",1,namestring);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue