~ chicken-core (chicken-5) f309a1c61b413509eb5f0d4f805388a55fe4ff4a


commit f309a1c61b413509eb5f0d4f805388a55fe4ff4a
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sat Nov 24 12:30:08 2018 +0100
Commit:     Moritz Heidkamp <moritz.heidkamp@bevuta.com>
CommitDate: Sun Nov 25 11:59:25 2018 +0100

    Change definition of "link", "chroot" and "C_getenv" from c-string to nonnull-c-string to fix C compiler warnings
    
    In file-link and set-root-directory! we already checked the argument
    for being a string.  In get-environment we did not do that, which
    meant #f would be passed to getenv() directly, causing a segfault.

diff --git a/NEWS b/NEWS
index f59d72ec..0841ea08 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@
   - Add the system-config-directory and system-cache-directory procedures
     in the chicken.platform module. These procedures follow the XDG
     specification and also give sensible results on Windows.
+  - Fix get-environment from (chicken process-context) to raise an
+     error when passed #f instead of segfaulting.
 
 
 5.0.0
diff --git a/library.scm b/library.scm
index 24f7c268..0891f6a4 100644
--- a/library.scm
+++ b/library.scm
@@ -5971,7 +5971,7 @@ static C_word C_fcall C_setenv(C_word x, C_word y) {
 ;;; Environment access:
 
 (define get-environment-variable
-  (foreign-lambda c-string "C_getenv" c-string))
+  (foreign-lambda c-string "C_getenv" nonnull-c-string))
 
 (define (set-environment-variable! var val)
   (##sys#check-string var 'set-environment-variable!)
diff --git a/posixunix.scm b/posixunix.scm
index e569ce97..a85f9dce 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -771,7 +771,7 @@ static int set_file_mtime(char *filename, C_word atime, C_word mtime)
 	(##sys#read-symbolic-link fname 'read-symbolic-link))))
 
 (set! chicken.file.posix#file-link
-  (let ([link (foreign-lambda int "link" c-string c-string)])
+  (let ((link (foreign-lambda int "link" nonnull-c-string nonnull-c-string)))
     (lambda (old new)
       (##sys#check-string old 'file-link)
       (##sys#check-string new 'file-link)
@@ -1284,7 +1284,7 @@ static int set_file_mtime(char *filename, C_word atime, C_word mtime)
 ;;; chroot:
 
 (set! chicken.process-context.posix#set-root-directory!
-  (let ([chroot (foreign-lambda int "chroot" c-string)])
+  (let ((chroot (foreign-lambda int "chroot" nonnull-c-string)))
     (lambda (dir)
       (##sys#check-string dir 'set-root-directory!)
       (when (fx< (chroot dir) 0)
Trap