diff --git a/hunspell/src/hunspell/strmgr.cxx b/hunspell/src/hunspell/strmgr.cxx index f0cd094..708de18 100644 --- a/hunspell/src/hunspell/strmgr.cxx +++ b/hunspell/src/hunspell/strmgr.cxx @@ -15,10 +15,12 @@ int StrMgr::fail(const char * err, const char * par) { StrMgr::StrMgr(const char * str, const char * key) { linenum = 0; index = 0; + st = NULL; size = strlen(str); - if(size > 0) + if(size > 0) { st = strdup(str); - if (!st) fail(MSG_OPEN, "Buffer allocation failed in StrMgr."); + if (!st) fail(MSG_OPEN, "Buffer allocation failed in StrMgr."); + } } StrMgr::~StrMgr() diff --git a/src/Nodehun.cc b/src/Nodehun.cc index a96c50a..6e4a104 100644 --- a/src/Nodehun.cc +++ b/src/Nodehun.cc @@ -58,10 +58,25 @@ Napi::Object Nodehun::Init(Napi::Env env, Napi::Object exports) { return exports; } -Nodehun::Nodehun(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { +Nodehun::Nodehun(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info), context(NULL) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); + if (info.Length() != 2) { + Napi::Error::New(env, INVALID_NUMBER_OF_ARGUMENTS).ThrowAsJavaScriptException(); + return; + } + + if (!info[0].IsBuffer()) { + Napi::Error::New(env, INVALID_FIRST_ARGUMENT).ThrowAsJavaScriptException(); + return; + } + + if (!info[1].IsBuffer()) { + Napi::Error::New(env, INVALID_SECOND_ARGUMENT).ThrowAsJavaScriptException(); + return; + } + Napi::Buffer affixBuffer = info[0].As>(); Napi::Buffer dictionaryBuffer = info[1].As>();