sexp_c_string returns #f for NULL

This commit is contained in:
Alex Shinn 2014-08-24 16:49:20 +09:00
parent 424671e5cf
commit dc89521801

7
sexp.c
View file

@ -1045,8 +1045,11 @@ sexp sexp_make_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp len, sexp ch)
} }
sexp sexp_c_string (sexp ctx, const char *str, sexp_sint_t slen) { sexp sexp_c_string (sexp ctx, const char *str, sexp_sint_t slen) {
sexp_sint_t len = ((slen >= 0) ? slen : strlen(str)); sexp_sint_t len;
sexp s = sexp_make_string(ctx, sexp_make_fixnum(len), SEXP_VOID); sexp s;
if (str == NULL) return SEXP_FALSE;
len = ((slen >= 0) ? slen : strlen(str));
s = sexp_make_string(ctx, sexp_make_fixnum(len), SEXP_VOID);
if (sexp_exceptionp(s)) return s; if (sexp_exceptionp(s)) return s;
memcpy(sexp_string_data(s), str, len); memcpy(sexp_string_data(s), str, len);
sexp_string_data(s)[len] = '\0'; sexp_string_data(s)[len] = '\0';