Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ECL CFFI segfault
(ql:quickload :cffi)
(defpackage :sock-test
(:use :cl)
(:export :delay
(in-package :sock-test)
(defconstant +af-inet+ 2)
(cffi:defcstruct sockaddr-in
(sin-family :short)
(sin-port :unsigned-short)
(sin-addr :unsigned-int)
(sin-zero-0 :char)
(sin-zero-1 :char)
(sin-zero-2 :char)
(sin-zero-3 :char)
(sin-zero-4 :char)
(sin-zero-5 :char)
(sin-zero-6 :char)
(sin-zero-7 :char))
(defun create-sockaddr (address port)
(let ((sockaddr (cffi:foreign-alloc '(:pointer (:struct sockaddr-in))))
(size (cffi:foreign-type-size '(:struct sockaddr-in)))
(address (if (string= address "")
(cffi:foreign-funcall "memset" :pointer sockaddr :unsigned-char 0 :unsigned-char size)
(cffi:with-foreign-slots ((sin-family sin-port sin-addr) sockaddr (:struct sockaddr-in))
(setf sin-family +af-inet+
sin-port (cffi:foreign-funcall "htons" :int port :unsigned-short)
sin-addr (if address
(cffi:foreign-funcall "inet_addr" :string address :unsigned-long)
(cffi:foreign-funcall "htonl" :unsigned-long 0 :unsigned-long))))
(values sockaddr size)))
(compile 'create-sockaddr)
(create-sockaddr "" 80)

orthecreedence commented Jun 20, 2014

GDB trace:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 2724.0x19d8]
0x00000143 in ?? ()
(gdb) bt
#0  0x00000143 in ?? ()
#1  0x00000000 in ?? ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment