Skip to content

Commit

Permalink
Fixes bug in source map handling (credit to @am11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Oct 31, 2014
1 parent 8e29956 commit 8561dcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions sass_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ extern "C" {
free(ctx);
}

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

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

*array = arr;
*n = num;
*n = num - skip;
}

// helper for safe access to c_ctx
Expand Down Expand Up @@ -134,7 +134,7 @@ extern "C" {
c_ctx->error_message = 0;
c_ctx->error_status = 0;

copy_strings(cpp_ctx.get_included_files(), &c_ctx->included_files, &c_ctx->num_included_files);
copy_strings(cpp_ctx.get_included_files(), &c_ctx->included_files, &c_ctx->num_included_files, 1);
}
catch (Error& e) {
stringstream msg_stream;
Expand Down
8 changes: 4 additions & 4 deletions source_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ namespace Sass {
json_append_member(json_srcmap, "version", json_mknumber(3));

if (source_index.size() > 0) {
const char *include = includes[source_index[0]].c_str();
const char *include = file.c_str();
JsonNode *json_include = json_mkstring(include);
json_append_member(json_srcmap, "file", json_include);
}

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

const char *mappings = serialize_mappings().c_str();
JsonNode *json_mappings = json_mkstring(mappings);
string mappings = serialize_mappings();
JsonNode *json_mappings = json_mkstring(mappings.c_str());
json_append_member(json_srcmap, "mappings", json_mappings);

JsonNode *json_names = json_mkarray();
Expand Down

0 comments on commit 8561dcd

Please sign in to comment.