Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 8561dcd

Browse files
committed
Fixes bug in source map handling (credit to @am11)
1 parent 8e29956 commit 8561dcd

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

sass_interface.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ extern "C" {
7272
free(ctx);
7373
}
7474

75-
void copy_strings(const std::vector<std::string>& strings, char*** array, int* n) {
75+
void copy_strings(const std::vector<std::string>& strings, char*** array, int* n, int skip = 0) {
7676
int num = static_cast<int>(strings.size());
7777
char** arr = (char**) malloc(sizeof(char*)* num);
7878

79-
for(int i = 0; i < num; i++) {
80-
arr[i] = (char*) malloc(sizeof(char) * strings[i].size() + 1);
81-
std::copy(strings[i].begin(), strings[i].end(), arr[i]);
82-
arr[i][strings[i].size()] = '\0';
79+
for(int i = skip; i < num; i++) {
80+
arr[i-skip] = (char*) malloc(sizeof(char) * strings[i].size() + 1);
81+
std::copy(strings[i].begin(), strings[i].end(), arr[i-skip]);
82+
arr[i-skip][strings[i].size()] = '\0';
8383
}
8484

8585
*array = arr;
86-
*n = num;
86+
*n = num - skip;
8787
}
8888

8989
// helper for safe access to c_ctx
@@ -134,7 +134,7 @@ extern "C" {
134134
c_ctx->error_message = 0;
135135
c_ctx->error_status = 0;
136136

137-
copy_strings(cpp_ctx.get_included_files(), &c_ctx->included_files, &c_ctx->num_included_files);
137+
copy_strings(cpp_ctx.get_included_files(), &c_ctx->included_files, &c_ctx->num_included_files, 1);
138138
}
139139
catch (Error& e) {
140140
stringstream msg_stream;

source_map.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ namespace Sass {
2525
json_append_member(json_srcmap, "version", json_mknumber(3));
2626

2727
if (source_index.size() > 0) {
28-
const char *include = includes[source_index[0]].c_str();
28+
const char *include = file.c_str();
2929
JsonNode *json_include = json_mkstring(include);
3030
json_append_member(json_srcmap, "file", json_include);
3131
}
3232

3333
JsonNode *json_includes = json_mkarray();
34-
for (size_t i = 1; i < source_index.size(); ++i) {
34+
for (size_t i = 0; i < source_index.size(); ++i) {
3535
const char *include = includes[source_index[i]].c_str();
3636
JsonNode *json_include = json_mkstring(include);
3737
json_append_element(json_includes, json_include);
@@ -48,8 +48,8 @@ namespace Sass {
4848
}
4949
json_append_member(json_srcmap, "sourcesContent", json_contents);
5050

51-
const char *mappings = serialize_mappings().c_str();
52-
JsonNode *json_mappings = json_mkstring(mappings);
51+
string mappings = serialize_mappings();
52+
JsonNode *json_mappings = json_mkstring(mappings.c_str());
5353
json_append_member(json_srcmap, "mappings", json_mappings);
5454

5555
JsonNode *json_names = json_mkarray();

0 commit comments

Comments
 (0)