Skip to content

Commit 740b0e6

Browse files
authored
Merge pull request #196 from dahlia/no_more_strdup
Use sass_copy_c_string instead of strdup for portability
2 parents 65eabdd + 42b7665 commit 740b0e6

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pysass.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <string.h>
21
#include <Python.h>
32
#include <sass/context.h>
43

@@ -461,8 +460,8 @@ static Sass_Import_List _call_py_importer_f(
461460
/* We need to give copies of these arguments; libsass handles
462461
* deallocation of them later, whereas path_str is left flapping
463462
* in the breeze -- it's treated const, so that's okay. */
464-
if (source_str) source_str = strdup(source_str);
465-
if (sourcemap_str) sourcemap_str = strdup(sourcemap_str);
463+
if (source_str) source_str = sass_copy_c_string(source_str);
464+
if (sourcemap_str) sourcemap_str = sass_copy_c_string(sourcemap_str);
466465

467466
sass_imports[i] = sass_make_import_entry(
468467
path_str, source_str, sourcemap_str
@@ -527,7 +526,7 @@ PySass_compile_string(PyObject *self, PyObject *args) {
527526
return NULL;
528527
}
529528

530-
context = sass_make_data_context(strdup(string));
529+
context = sass_make_data_context(sass_copy_c_string(string));
531530
options = sass_data_context_get_options(context);
532531
sass_option_set_output_style(options, output_style);
533532
sass_option_set_source_comments(options, source_comments);
@@ -578,11 +577,8 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
578577
if (PyBytes_Check(source_map_filename)) {
579578
size_t source_map_file_len = PyBytes_GET_SIZE(source_map_filename);
580579
if (source_map_file_len) {
581-
char *source_map_file = (char *) malloc(source_map_file_len + 1);
582-
strncpy(
583-
source_map_file,
584-
PyBytes_AS_STRING(source_map_filename),
585-
source_map_file_len + 1
580+
char *source_map_file = sass_copy_c_string(
581+
PyBytes_AS_STRING(source_map_filename)
586582
);
587583
sass_option_set_source_map_file(options, source_map_file);
588584
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy