args = nltk_make_args_from_string(info);
lists = nltk_call_function_with_args(nltk_get_function_handle(globe_nltk,"word_tokenize"), args);
len = nltk_get_size_from_list(lists);
- char *tokens[128] = {NULL,};
+ char *tokens[BUF_LEN_128] = {NULL,};
for(int i = 0 ;i < len ;i++)
{
- tokens[i] = (char*)malloc(128*sizeof(char));
- strcpy(tokens[i] ,nltk_get_string_from_element(nltk_get_element_from_list_by_index(lists, i)));
+ tokens[i] = (char*)malloc(BUF_LEN_128*sizeof(char));
+ if(tokens[i]!=NULL)
+ {
+ memset(tokens[i], 0, BUF_LEN_128);
+ strncpy(tokens[i], nltk_get_string_from_element(nltk_get_element_from_list_by_index(lists, i)), BUF_LEN_128-1);
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
}
bundle_add_str(reply, "command", "word_tokenize");
bundle_add_str_array(reply, "return_token", tokens, len);
args = nltk_make_args_from_pyobject(lists);
postag_result = nltk_call_function_with_args(postag_module, args);
len = nltk_get_size_from_list(postag_result);
- char *tag[128] = {NULL,};
- char *token[128] = {NULL,};
+ char *tag[BUF_LEN_128] = {NULL,};
+ char *token[BUF_LEN_128] = {NULL,};
for(int i = 0 ;i < len ;i++)
{
- token[i] = (char*)malloc(128*sizeof(char));
- tag[i] = (char*)malloc(128*sizeof(char));
+ token[i] = (char*)malloc(BUF_LEN_128*sizeof(char));
+ tag[i] = (char*)malloc(BUF_LEN_128*sizeof(char));
pos_elm_tuple = nltk_get_element_from_list_by_index(postag_result, i);
- strcpy(tag[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 0)));
- strcpy(token[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 1)));
+ if(tag[i]!=NULL)
+ {
+ memset(tag[i], 0, BUF_LEN_128);
+ strncpy(tag[i], nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 0)), BUF_LEN_128-1);
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
+ if(token[i]!=NULL)
+ {
+ memset(token[i], 0, BUF_LEN_128);
+ strncpy(token[i], nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 1)), BUF_LEN_128-1);
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
}
bundle_add_str(reply, "command", "pos_tag");
bundle_add_str_array(reply, "return_tag", tag, len);
lv_module = nltk_get_function_handle(ne_result, "leaves");
lv_result = nltk_call_function_with_args(lv_module, NULL);
len = nltk_get_size_from_list(lv_result);
- char *s_tag[128] = {NULL,};
- char *s_token[128] = {NULL,};
+ char *s_tag[BUF_LEN_128] = {NULL,};
+ char *s_token[BUF_LEN_128] = {NULL,};
for(int i = 0 ;i < len ;i++)
{
- s_token[i] = (char*)malloc(128*sizeof(char));
- s_tag[i] = (char*)malloc(128*sizeof(char));
+ s_token[i] = (char*)malloc(BUF_LEN_128*sizeof(char));
+ s_tag[i] = (char*)malloc(BUF_LEN_128*sizeof(char));
pos_elm_tuple = nltk_get_element_from_list_by_index(lv_result, i);
- strcpy(s_tag[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 0)));
- strcpy(s_token[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 1)));
+ if(s_tag[i]!=NULL)
+ {
+ memset(s_tag[i], 0, BUF_LEN_128);
+ strncpy(s_tag[i], nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 0)), BUF_LEN_128-1);
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
+ if(s_token[i]!=NULL)
+ {
+ memset(s_token[i], 0, BUF_LEN_128);
+ strncpy(s_token[i], nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 1)), BUF_LEN_128-1);
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
}
bundle_add_str(reply, "command", "ne_chunk");
bundle_add_str_array(reply, "return_tag", s_tag, len);
lm_module = nltk_get_function_handle(lm_object, "lemmatize");
lm_result = nltk_call_function_with_args(lm_module, args);
char *lem_buf[1] = {NULL,};
- lem_buf[0] = (char*)malloc(128*sizeof(char));
- strcpy(lem_buf[0] , nltk_get_string_from_element(lm_result));
- bundle_add_str(reply, "command", "lemmatize");
- bundle_add_str_array(reply, "return_token", lem_buf, 1);
- PINFO("lemmatize process done");
+ lem_buf[0] = (char*)malloc(BUF_LEN_128*sizeof(char));
+ if(lem_buf[0]!=NULL)
+ {
+ memset(lem_buf[0], 0, BUF_LEN_128);
+ strncpy(lem_buf[0], nltk_get_string_from_element(lm_result), BUF_LEN_128-1);
+ bundle_add_str(reply, "command", "lemmatize");
+ bundle_add_str_array(reply, "return_token", lem_buf, 1);
+ PINFO("lemmatize process done");
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
break;
case NLTK_CMD_LANGDETECT:
args = nltk_make_args_from_string(info);
ld_module = nltk_get_function_handle(globe_lang,"detect");
ld_result = nltk_call_function_with_args(ld_module, args);
char *lang_buf[1] = {NULL,};
- lang_buf[0] = (char*)malloc(128*sizeof(char));
- strcpy(lang_buf[0] , nltk_get_string_from_element(ld_result));
- bundle_add_str(reply, "command", "langdetect");
- bundle_add_str_array(reply, "return_token", lang_buf, 1);
- PINFO("langdetect process done");
+ lang_buf[0] = (char*)malloc(BUF_LEN_128*sizeof(char));
+ if(lang_buf[0]!=NULL)
+ {
+ memset(lang_buf[0], 0, BUF_LEN_128);
+ strncpy(lang_buf[0], nltk_get_string_from_element(ld_result), BUF_LEN_128-1);
+ bundle_add_str(reply, "command", "langdetect");
+ bundle_add_str_array(reply, "return_token", lang_buf, 1);
+ PINFO("langdetect process done");
+ }
+ else
+ {
+ PERR("malloc failed");
+ }
break;
default:
PWARNING("unkonw command, command = [%s]", message);
char* nltk_get_string_from_element(PyObject* elm)
{
PRET_VM(!elm, NULL, "Input parameter [elm] is NULL!");
- char* ch = (char*) malloc(255);
- strcpy(ch, PyString_AsString(elm));
+ char* ch = (char*) malloc(BUF_LEN_256);
+ if(ch == NULL)
+ {
+ PERR("malloc failed");
+ return ch;
+ }
+ memset(ch, 0, BUF_LEN_256);
+ strncpy(ch, PyString_AsString(elm), BUF_LEN_256-1);
return ch;
}
{
PyObject *pModule, *pFunc;
PyObject *pArgs;
- char* ch = (char*) malloc(255);
+ char* ch = (char*) malloc(BUF_LEN_256);
if (ch != NULL)
{
+ memset(ch, 0, BUF_LEN_256);
pModule = PyImport_ImportModule("site");
if (pModule != NULL)
{
//call word_tokenize func with args
pFunc = PyObject_GetAttrString(pModule, "USER_SITE");
if (pFunc != NULL) {
- strcpy(ch, PyString_AsString(pFunc));
+ strncpy(ch, PyString_AsString(pFunc), BUF_LEN_256-1);
} else {
- strcpy(ch, "attribute get error\n");
+ strncpy(ch, "attribute get error\n", BUF_LEN_256-1);
}
} else {
- strcpy(ch, "nltk module import error\n");
+ strncpy(ch, "nltk module import error\n", BUF_LEN_256-1);
}
return ch;
}
else
{
+ PERR("malloc failed");
return NULL;
}
}