Hello,

the attached code produces

$ ./a.out
foo,bar
bar

while I would expect

$ ./a.out
foo
bar

Similar behavior can be produced with `substring', but `substring/copy'
will work as expected.  So I suspect this is some issue with strings
sharing memory and a missing '0' when scm_to_latin1_string calls
scm_strdup.

David

#include <libguile.h>

/*
  This outputs:

  dhansen@localhorst ~/tmp $ ./a.out
  foo,bar
  bar

*/

static void
inner_main (void *data, int argc, char **argv)
{
  char *cstr;

  SCM string = scm_from_latin1_string ("foo,bar");
  SCM tokens = scm_string_split (string, SCM_MAKE_CHAR (','));
  SCM tok;

  for (tok = tokens; !scm_is_null (tok); tok = scm_cdr (tok))
    {
      cstr = scm_to_latin1_string (scm_car (tok));
      printf ("%s\n", cstr);
      free (cstr);
    }
}

int
main (int argc, char **argv)
{
  scm_boot_guile (argc, argv, inner_main, NULL);
}

/* Local Variables: */
/* compile-command: "gcc `pkg-config --cflags --libs guile-2.0` main.c" */
/* End: */

Reply via email to