!482 [Bug]: 部分代码不规范

Merge pull request !482 from 田迅/master
This commit is contained in:
openharmony_ci 2024-11-07 13:02:10 +00:00 committed by Gitee
commit 547dc62e5b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 66 additions and 52 deletions

View File

@ -308,11 +308,13 @@ void NapiPrintUtils::DefineProperties(
std::string NapiPrintUtils::GetValueString(napi_env env, napi_value value) std::string NapiPrintUtils::GetValueString(napi_env env, napi_value value)
{ {
std::string resultValue = ""; std::string resultValue = "";
char value_string[256]; char value_string[256] = { 0 };
size_t value_size = 256; size_t value_size = 256;
size_t result; size_t result = 0;
napi_get_value_string_utf8(env, value, value_string, value_size, &result); napi_status status = napi_get_value_string_utf8(env, value, value_string, value_size, &result);
resultValue = value_string; if (status == napi_ok && result > 0) {
resultValue = value_string;
}
return resultValue; 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, void PrintAttributesHelper::BuildJsWorkerIsLegal(napi_env env, napi_value jsValue,
std::shared_ptr<PrintAttributes> &nativeObj) std::shared_ptr<PrintAttributes> &nativeObj)
{ {
if (nativeObj == nullptr) {
PRINT_HILOGE("nativeObj is nullptr");
return;
}
napi_value jsPageRange = NapiPrintUtils::GetNamedProperty(env, jsValue, PARAM_JOB_PAGERANGE); napi_value jsPageRange = NapiPrintUtils::GetNamedProperty(env, jsValue, PARAM_JOB_PAGERANGE);
if (jsPageRange != nullptr) { if (jsPageRange != nullptr) {
auto pageRangePtr = PrintRangeHelper::BuildFromJs(env, jsPageRange); 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; napi_value jsResolutionList = nullptr;
PRINT_CALL_BASE(env, napi_create_array(env, &jsResolutionList), false); PRINT_CALL_BASE(env, napi_create_array(env, &jsResolutionList), false);
std::vector<PrintResolution> resolutionList; std::vector<PrintResolution> resolutionList;
cap.GetResolution(resolutionList);
uint32_t arrLength = resolutionList.size(); uint32_t arrLength = resolutionList.size();
for (uint32_t index = 0; index < arrLength; index++) { for (uint32_t index = 0; index < arrLength; index++) {

View File

@ -283,7 +283,7 @@ napi_value NapiScanUtils::CreateBoolean(napi_env env, bool value)
bool NapiScanUtils::GetBooleanFromValue(napi_env env, napi_value 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); SCAN_CALL_BASE(env, napi_get_value_bool(env, value, &ret), 0);
return ret; return ret;
} }
@ -330,11 +330,13 @@ std::string NapiScanUtils::ToLower(const std::string &s)
std::string NapiScanUtils::GetValueString(napi_env env, napi_value value) std::string NapiScanUtils::GetValueString(napi_env env, napi_value value)
{ {
std::string resultValue = ""; std::string resultValue = "";
char value_string[256]; char value_string[256] = { 0 };
size_t value_size = 256; size_t value_size = 256;
size_t result; size_t result = 0;
napi_get_value_string_utf8(env, value, value_string, value_size, &result); napi_status status = napi_get_value_string_utf8(env, value, value_string, value_size, &result);
resultValue = value_string; if (status == napi_ok && result > 0) {
resultValue = value_string;
}
return resultValue; return resultValue;
} }
@ -420,7 +422,7 @@ uint32_t NapiScanUtils::GetIdFromFdPath(const std::string &fdPath)
{ {
std::string fd_str = fdPath.substr(fdPath.rfind('/') + 1, fdPath.length()); std::string fd_str = fdPath.substr(fdPath.rfind('/') + 1, fdPath.length());
std::stringstream getStrStream(fd_str); std::stringstream getStrStream(fd_str);
uint32_t fd; uint32_t fd = 0;
if (!(getStrStream >> fd)) { if (!(getStrStream >> fd)) {
SCAN_HILOGD("failed to convert to uint32"); 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) { if (work->data == nullptr) {
PRINT_HILOGE("data is nullptr"); PRINT_HILOGE("data is nullptr");
delete work;
work = nullptr;
return false; return false;
} }
CallbackParam *cbParam = reinterpret_cast<CallbackParam *>(work->data); 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) { if (scope == nullptr) {
PRINT_HILOGE("fail to open scope"); PRINT_HILOGE("fail to open scope");
delete cbParam; delete cbParam;
work->data = nullptr; cbParam = nullptr;
delete work;
work = nullptr;
return false; return false;
} }
return true; return true;
@ -122,13 +126,13 @@ static void PrintTaskAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult); callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintTaskAfterCallFun success"); PRINT_HILOGI("OnCallback end run PrintTaskAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
static void PrinterAfterCallFun(uv_work_t *work, int status) static void PrinterAfterCallFun(uv_work_t *work, int status)
@ -150,13 +154,13 @@ static void PrinterAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult); callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrinterAfterCallFun success"); PRINT_HILOGI("OnCallback end run PrinterAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
static void PrintJobAfterCallFun(uv_work_t *work, int status) static void PrintJobAfterCallFun(uv_work_t *work, int status)
@ -180,13 +184,13 @@ static void PrintJobAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult); callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintJobAfterCallFun success"); PRINT_HILOGI("OnCallback end run PrintJobAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
static void ExtensionAfterCallFun(uv_work_t *work, int status) static void ExtensionAfterCallFun(uv_work_t *work, int status)
@ -210,13 +214,13 @@ static void ExtensionAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult); callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run ExtensionAfterCallFun success"); PRINT_HILOGI("OnCallback end run ExtensionAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
static void PrintAdapterAfterCallFun(uv_work_t *work, int status) 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); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintAdapterAfterCallFun success"); PRINT_HILOGI("OnCallback end run PrintAdapterAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
static void PrintAdapterJobStateChangedAfterCallFun(uv_work_t *work, int status) 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); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintAdapterJobStateChangedAfterCallFun success"); PRINT_HILOGI("OnCallback end run PrintAdapterJobStateChangedAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
static void PrintAdapterGetFileAfterCallFun(uv_work_t *work, int status) static void PrintAdapterGetFileAfterCallFun(uv_work_t *work, int status)
@ -324,13 +328,13 @@ static void PrintAdapterGetFileAfterCallFun(uv_work_t *work, int status)
callbackValues, &callbackResult); callbackValues, &callbackResult);
napi_close_handle_scope(cbParam->env, scope); napi_close_handle_scope(cbParam->env, scope);
PRINT_HILOGI("OnCallback end run PrintAdapterGetFileAfterCallFun success"); PRINT_HILOGI("OnCallback end run PrintAdapterGetFileAfterCallFun success");
if (work != nullptr) {
delete work;
work = nullptr;
}
delete cbParam; delete cbParam;
cbParam = nullptr; cbParam = nullptr;
} }
if (work != nullptr) {
delete work;
work = nullptr;
}
} }
bool PrintCallback::onBaseCallback(std::function<void(CallbackParam*)> paramFun, uv_after_work_cb after_work_cb) 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()) { if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second; auto requestFunc = itFunc->second;
if (requestFunc != nullptr) { if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply); return static_cast<int32_t>((this->*requestFunc)(data, reply));
} }
} }
PRINT_HILOGW("default case, need check."); PRINT_HILOGW("default case, need check.");

View File

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

View File

@ -44,7 +44,7 @@ int32_t ScanCallbackStub::OnRemoteRequest(
if (itFunc != cmdMap_.end()) { if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second; auto requestFunc = itFunc->second;
if (requestFunc != nullptr) { if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply); return static_cast<int32_t>((this->*requestFunc)(data, reply));
} }
} }
SCAN_HILOGW("default case, need check."); 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 ErrCode PrintExtensionContext::StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const
{ {
PRINT_HILOGD("%{public}s begin.", __func__); PRINT_HILOGD("%{public}s begin.", __func__);
PRINT_HILOGD("%{public}d accountId:", accountId); PRINT_HILOGD("%{private}d accountId:", accountId);
ErrCode err = ErrCode err =
AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, ILLEGAL_REQUEST_CODE, accountId); AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, ILLEGAL_REQUEST_CODE, accountId);
PRINT_HILOGD("%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err); PRINT_HILOGD("%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err);

View File

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

View File

@ -115,6 +115,7 @@ void PrintBMSHelper::ResetProxy(const wptr<IRemoteObject> &remote)
PRINT_HILOGD("need reset"); PRINT_HILOGD("need reset");
serviceRemote->RemoveDeathRecipient(printBMSDeath_); serviceRemote->RemoveDeathRecipient(printBMSDeath_);
sptrBundleMgr_ = nullptr; sptrBundleMgr_ = nullptr;
delete printBMSDeath_;
printBMSDeath_ = nullptr; printBMSDeath_ = nullptr;
} }
} }

View File

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