From c4676cdd92872b6459438031335022a4d82134f5 Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Tue, 26 Jul 2022 10:59:00 +0800 Subject: [PATCH] =?UTF-8?q?osfullname=20=E9=80=82=E9=85=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- interfaces/innerkits/syspara/param_comm.c | 6 ++---- interfaces/innerkits/syspara/parameter.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/syspara/param_comm.c b/interfaces/innerkits/syspara/param_comm.c index 9e47b9e6..508e2ebc 100644 --- a/interfaces/innerkits/syspara/param_comm.c +++ b/interfaces/innerkits/syspara/param_comm.c @@ -33,8 +33,6 @@ #include "securec.h" #include "beget_ext.h" -static const char *g_emptyStr = ""; - INIT_LOCAL_API int IsValidParamValue(const char *value, uint32_t len) { if ((value == NULL) || (strlen(value) + 1 > len)) { @@ -73,11 +71,11 @@ INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder int ret = SystemGetParameter(key, NULL, &len); if (ret == 0 && len > 0) { char *res = (char *)malloc(len + 1); - BEGET_CHECK(res != NULL, return g_emptyStr); + BEGET_CHECK(res != NULL, return NULL); ret = SystemGetParameter(key, res, &len); if (ret != 0) { free(res); - return g_emptyStr; + return NULL; } *paramHolder = res; } diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c index 8d630599..28a312b5 100644 --- a/interfaces/innerkits/syspara/parameter.c +++ b/interfaces/innerkits/syspara/parameter.c @@ -241,17 +241,20 @@ int GetDevUdid(char *udid, int size) static const char *BuildOSFullName(void) { const char release[] = "Release"; - char value[OS_FULL_NAME_LEN] = {0}; const char *releaseType = GetOsReleaseType(); const char *fillname = GetFullName_(); if ((releaseType != NULL) && (strncmp(releaseType, release, sizeof(release) - 1) != 0)) { + char *value = calloc(1, OS_FULL_NAME_LEN); + if (value == NULL) { + return NULL; + } int length = sprintf_s(value, OS_FULL_NAME_LEN, "%s(%s)", fillname, releaseType); if (length < 0) { - return EMPTY_STR; + return NULL; } } - const char *osFullName = strdup(value); - return osFullName; + + return strdup(fillname); } const char *GetOSFullName(void) @@ -270,13 +273,16 @@ const char *GetOSFullName(void) static const char *BuildVersionId(void) { char value[VERSION_ID_MAX_LEN] = {0}; + if (GetDeviceType() == NULL) { + return NULL; + } int len = sprintf_s(value, VERSION_ID_MAX_LEN, "%s/%s/%s/%s/%s/%s/%s/%s/%s/%s", GetDeviceType(), GetManufacture(), GetBrand(), GetProductSeries(), GetOSFullName(), GetProductModel(), GetSoftwareModel(), GetSdkApiVersion_(), GetIncrementalVersion(), GetBuildType()); if (len <= 0) { - return EMPTY_STR; + return NULL; } const char *versionId = strdup(value); return versionId; -- GitLab