diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 6333fa153..531ce3669 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -981,27 +981,14 @@ String *CFFI::lispify_name(Node *n, String *ty, const char *flag, bool kw) { /* utilities */ /* returns new string w/ parens stripped */ String *CFFI::strip_parens(String *string) { - char *s = Char(string), *p; + char *s = Char(string); int len = Len(string); - String *res; if (len == 0 || s[0] != '(' || s[len - 1] != ')') { return NewString(string); } - p = (char *) malloc(len - 2 + 1); - if (!p) { - Printf(stderr, "Malloc failed\n"); - SWIG_exit(EXIT_FAILURE); - } - - strncpy(p, s + 1, len - 1); - p[len - 2] = 0; /* null terminate */ - - res = NewString(p); - free(p); - - return res; + return NewStringWithSize(s + 1, len - 2); } String *CFFI::trim(String *str) { diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index d7d3da8fc..03e777cf4 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -947,20 +947,16 @@ public: if (!is_setter) { /* Strip off "-get" */ - char *pws_name = (char *) malloc(sizeof(char) * (len - 3)); - strncpy(pws_name, pc, len - 3); - pws_name[len - 4] = 0; if (struct_member == 2) { /* There was a setter, so create a procedure with setter */ Printf(f_init, "scm_c_define"); - Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(getter, setter));\n", pws_name); + Printf(f_init, "(\"%.*s\", " "scm_make_procedure_with_setter(getter, setter));\n", pc, len - 4); } else { /* There was no setter, so make an alias to the getter */ Printf(f_init, "scm_c_define"); - Printf(f_init, "(\"%s\", getter);\n", pws_name); + Printf(f_init, "(\"%.*s\", getter);\n", pc, len - 4); } - Printf(exported_symbols, "\"%s\", ", pws_name); - free(pws_name); + Printf(exported_symbols, "\"%.*s\", ", pc, len - 4); } } else { /* Register the function */ diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index ebd788d35..1f7ff044a 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -471,9 +471,7 @@ static void getoptions(int argc, char *argv[]) { Swig_mark_arg(i); } else if (strncmp(argv[i], "-I", 2) == 0) { // Add a new directory search path - char *a = Swig_copy_string(argv[i] + 2); - Swig_add_directory((DOH *) a); - free(a); + Swig_add_directory((String_or_char*)(argv[i] + 2)); Swig_mark_arg(i); } else if (strncmp(argv[i], "-D", 2) == 0) { String *d = NewString(argv[i] + 2);