Skip to content

Commit

Permalink
Fixing the build
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Sep 12, 2015
1 parent 624c413 commit 002c8ea
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions csrc/addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,24 @@ void Convert(const FunctionCallbackInfo<Value>& args) {
reinterpret_cast<const uint8_t*>(input_data), input_length);
size_t actual_output_length = max_output_length;

char* output_data = static_cast<char*>(malloc(max_output_length));
if (output_data == nullptr) {
free(output_data);
args.GetReturnValue().Set(Local<Object>());
return;
}
char* output_data[max_output_length];

// Create the Woff2 font
if (!woff2::ConvertTTFToWOFF2(
reinterpret_cast<const uint8_t*>(input_data), input_length,
reinterpret_cast<uint8_t*>(output_data), &actual_output_length
)) {
free(output_data);
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Could not convert the given font.")));
return;
}

// Reallocate the buffer data if needed
if (actual_output_length < max_output_length) {
output_data = static_cast<char*>(realloc(output_data, actual_output_length));
if (output_data == nullptr) {
free(output_data);
args.GetReturnValue().Set(Local<Object>());
return;
}
}

Local<Object> outputBuffer;
if (!node::Buffer::New(isolate, output_data, actual_output_length).ToLocal(&outputBuffer)) {
free(output_data);
if (!node::Buffer::Copy(
isolate,
reinterpret_cast<const char*>(output_data),
actual_output_length
).ToLocal(&outputBuffer)) {
args.GetReturnValue().Set(Local<Object>());
return;
}
Expand Down

0 comments on commit 002c8ea

Please sign in to comment.