!476 修复稳定性问题

Merge pull request !476 from 张智勇/master
This commit is contained in:
openharmony_ci 2024-11-05 07:36:10 +00:00 committed by 田迅
commit 8e4583dc3a
11 changed files with 66 additions and 53 deletions

View File

@ -308,11 +308,13 @@ void NapiPrintUtils::DefineProperties(
std::string NapiPrintUtils::GetValueString(napi_env env, napi_value value)
{
std::string resultValue = "";
char value_string[256];
char value_string[256] = { 0 };
size_t value_size = 256;
size_t result;
napi_get_value_string_utf8(env, value, value_string, value_size, &result);
resultValue = value_string;
size_t result = 0;
napi_status status = napi_get_value_string_utf8(env, value, value_string, value_size, &result);
if (status == napi_ok && result > 0) {
resultValue = value_string;
}
return resultValue;
}

View File

@ -110,6 +110,10 @@ std::shared_ptr<PrintAttributes> PrintAttributesHelper::BuildFromJs(napi_env env
void PrintAttributesHelper::BuildJsWorkerIsLegal(napi_env env, napi_value jsValue,
std::shared_ptr<PrintAttributes> &nativeObj)
{
if (nativeObj == nullptr) {
PRINT_HILOGE("nativeObj is nullptr");
return;
}
napi_value jsPageRange = NapiPrintUtils::GetNamedProperty(env, jsValue, PARAM_JOB_PAGERANGE);
if (jsPageRange != nullptr) {
auto pageRangePtr = PrintRangeHelper::BuildFromJs(env, jsPageRange);

View File

@ -106,6 +106,7 @@ bool PrinterCapabilityHelper::CreateResolutionList(napi_env env, napi_value &jsP
napi_value jsResolutionList = nullptr;
PRINT_CALL_BASE(env, napi_create_array(env, &jsResolutionList), false);
std::vector<PrintResolution> resolutionList;
cap.GetResolution(resolutionList);
uint32_t arrLength = resolutionList.size();
for (uint32_t index = 0; index < arrLength; index++) {

View File

@ -282,7 +282,7 @@ napi_value NapiScanUtils::CreateBoolean(napi_env env, bool value)
bool NapiScanUtils::GetBooleanFromValue(napi_env env, napi_value value)
{
bool ret = 0;
bool ret = false;
SCAN_CALL_BASE(env, napi_get_value_bool(env, value, &ret), 0);
return ret;
}
@ -329,11 +329,13 @@ std::string NapiScanUtils::ToLower(const std::string &s)
std::string NapiScanUtils::GetValueString(napi_env env, napi_value value)
{
std::string resultValue = "";
char value_string[256];
char value_string[256] = { 0 };
size_t value_size = 256;
size_t result;
napi_get_value_string_utf8(env, value, value_string, value_size, &result);
resultValue = value_string;
size_t result = 0;
napi_status status = napi_get_value_string_utf8(env, value, value_string, value_size, &result);
if (status == napi_ok && result > 0) {
resultValue = value_string;
}
return resultValue;
}
@ -415,7 +417,7 @@ uint32_t NapiScanUtils::GetIdFromFdPath(const std::string &fdPath)
{
std::string fd_str = fdPath.substr(fdPath.rfind('/') + 1, fdPath.length());
std::stringstream getStrStream(fd_str);
uint32_t fd;
uint32_t fd = 0;
if (!(getStrStream >> fd)) {
SCAN_HILOGD("failed to convert to uint32");
}

View File

@ -91,6 +91,8 @@ static bool InitUvWorkCallbackEnv(uv_work_t *work, napi_handle_scope &scope)
}
if (work->data == nullptr) {
PRINT_HILOGE("data is nullptr");
delete work;
work = nullptr;
return false;
}
CallbackParam *cbParam = reinterpret_cast<CallbackParam *>(work->data);
@ -98,7 +100,9 @@ static bool InitUvWorkCallbackEnv(uv_work_t *work, napi_handle_scope &scope)
if (scope == nullptr) {
PRINT_HILOGE("fail to open scope");
delete cbParam;
work->data = nullptr;
cbParam = nullptr;
delete work;
work = nullptr;
return false;
}
return true;
@ -122,13 +126,13 @@ static void PrintTaskAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintTaskAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
static void PrinterAfterCallFun(uv_work_t *work, int status)
@ -150,13 +154,13 @@ static void PrinterAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrinterAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
static void PrintJobAfterCallFun(uv_work_t *work, int status)
@ -180,13 +184,13 @@ static void PrintJobAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintJobAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
static void ExtensionAfterCallFun(uv_work_t *work, int status)
@ -210,13 +214,13 @@ static void ExtensionAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run ExtensionAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
static void PrintAdapterAfterCallFun(uv_work_t *work, int status)
@ -263,13 +267,13 @@ static void PrintAdapterAfterCallFun(uv_work_t *work, int status)
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintAdapterAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
static void PrintAdapterJobStateChangedAfterCallFun(uv_work_t *work, int status)
@ -297,13 +301,13 @@ static void PrintAdapterJobStateChangedAfterCallFun(uv_work_t *work, int status)
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintAdapterJobStateChangedAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
static void PrintAdapterGetFileAfterCallFun(uv_work_t *work, int status)
@ -324,13 +328,13 @@ static void PrintAdapterGetFileAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintAdapterGetFileAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam;
cbParam = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
bool PrintCallback::onBaseCallback(std::function<void(CallbackParam*)> paramFun, uv_after_work_cb after_work_cb)

View File

@ -44,7 +44,7 @@ int32_t PrintCallbackStub::OnRemoteRequest(
if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second;
if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply);
return static_cast<int32_t>((this->*requestFunc)(data, reply));
}
}
PRINT_HILOGW("default case, need check.");

View File

@ -43,7 +43,7 @@ int32_t PrintExtensionCallbackStub::OnRemoteRequest(
if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second;
if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply);
return static_cast<int32_t>((this->*requestFunc)(data, reply));
}
}
PRINT_HILOGW("default case, need check.");

View File

@ -44,7 +44,7 @@ int32_t ScanCallbackStub::OnRemoteRequest(
if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second;
if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply);
return static_cast<int32_t>((this->*requestFunc)(data, reply));
}
}
SCAN_HILOGW("default case, need check.");

View File

@ -59,7 +59,7 @@ bool PrintExtensionContext::ConnectAbility(
ErrCode PrintExtensionContext::StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const
{
PRINT_HILOGD("%{public}s begin.", __func__);
PRINT_HILOGD("%{public}d accountId:", accountId);
PRINT_HILOGD("%{private}d accountId:", accountId);
ErrCode err =
AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, ILLEGAL_REQUEST_CODE, accountId);
PRINT_HILOGD("%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err);

View File

@ -164,7 +164,7 @@ uint32_t PrintUtils::GetIdFromFdPath(const std::string &fdPath)
{
std::string fd_str = fdPath.substr(fdPath.rfind('/') + 1, fdPath.length());
std::stringstream getStrStream(fd_str);
uint32_t fd;
uint32_t fd = 0;
if (!(getStrStream >> fd)) {
PRINT_HILOGD("failed to convert to uint32");
}

View File

@ -412,8 +412,8 @@ void PrintCupsClient::StopCupsdService()
void PrintCupsClient::QueryPPDInformation(const char *makeModel, std::vector<std::string> &ppds)
{
ipp_t *request;
ipp_t *response;
ipp_t *request = nullptr;
ipp_t *response = nullptr;
const char *ppd_make_model;
const char *ppd_name;
@ -482,7 +482,7 @@ int32_t PrintCupsClient::AddPrinterToCups(const std::string &printerUri, const s
const std::string &printerMake)
{
PRINT_HILOGD("PrintCupsClient AddPrinterToCups start, printerMake: %{public}s", printerMake.c_str());
ipp_t *request;
ipp_t *request = nullptr;
char uri[HTTP_MAX_URI] = {0};
std::vector<string> ppds;
std::string ppd = DEFAULT_PPD_NAME;
@ -580,7 +580,7 @@ int32_t PrintCupsClient::AddPrinterToCupsWithPpd(const std::string &printerUri,
int32_t PrintCupsClient::DeleteCupsPrinter(const char *printerName)
{
ipp_t *request;
ipp_t *request = nullptr;
char uri[HTTP_MAX_URI] = {0};
PRINT_HILOGD("PrintCupsClient DeleteCupsPrinter start: %{private}s", printerName);
@ -889,7 +889,7 @@ int32_t PrintCupsClient::QueryAddedPrinterList(std::vector<std::string> &printer
int32_t PrintCupsClient::SetDefaultPrinter(const std::string &printerName)
{
http_t *http;
http_t *http = nullptr;
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
@ -900,7 +900,7 @@ int32_t PrintCupsClient::SetDefaultPrinter(const std::string &printerName)
PRINT_HILOGE("cups server is not alive");
return E_PRINT_SERVER_FAILURE;
}
ipp_t *request; /* IPP Request */
ipp_t *request = nullptr; /* IPP Request */
char uri[HTTP_MAX_URI] = {0}; /* URI for printer/class */
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
"localhost", 0, "/printers/%s", printerName.c_str());
@ -1224,7 +1224,7 @@ void PrintCupsClient::MonitorJobState(JobMonitorParam *param, CallbackFunc callb
if (param == nullptr) {
return;
}
http_t *http = NULL;
http_t *http = nullptr;
uint32_t fail_connect_times = 0;
ippSetPort(CUPS_SEVER_PORT);
http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, LONG_TIME_OUT, NULL);
@ -1435,7 +1435,7 @@ void PrintCupsClient::QueryJobState(http_t *http, JobMonitorParam *param, JobSta
bool PrintCupsClient::CheckPrinterOnline(JobMonitorParam *param, const uint32_t timeout)
{
http_t *http;
http_t *http = nullptr;
char scheme[32] = {0};
char userpass[BUFFER_LEN] = {0};
char host[BUFFER_LEN] = {0};
@ -1645,7 +1645,7 @@ std::string PrintCupsClient::GetColorString(uint32_t colorCode)
bool PrintCupsClient::IsCupsServerAlive()
{
http_t *http;
http_t *http = nullptr;
ippSetPort(CUPS_SEVER_PORT);
http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, LONG_TIME_OUT, NULL);
if (http == nullptr) {