mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-01-06 08:04:55 +00:00
Remove ASSERT in lib functions
Replace ASSERT in lib functions with error message print and return a value indicating error to allow the caller of lib functions to handle the error. Change-Id: If166484238dc0734041adfdbb19a5b374c044e33 Signed-off-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
@@ -63,8 +63,10 @@ char *strcpy_s(char *d, size_t dmax, const char *s)
|
||||
size_t dest_avail;
|
||||
uint64_t overlap_guard;
|
||||
|
||||
ASSERT(s != NULL, "invalid input s.");
|
||||
ASSERT((d != NULL) && (dmax != 0), "invalid input d or dmax.");
|
||||
if (s == NULL || d == NULL || dmax == 0) {
|
||||
pr_err("%s: invalid src, dest buffer or length.", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (s == d)
|
||||
return d;
|
||||
@@ -75,7 +77,11 @@ char *strcpy_s(char *d, size_t dmax, const char *s)
|
||||
dest_base = d;
|
||||
|
||||
while (dest_avail > 0) {
|
||||
ASSERT(overlap_guard != 0, "overlap happened.");
|
||||
if (overlap_guard == 0) {
|
||||
pr_err("%s: overlap happened.", __func__);
|
||||
*(--d) = '\0';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*d = *s;
|
||||
if (*d == '\0')
|
||||
@@ -87,7 +93,7 @@ char *strcpy_s(char *d, size_t dmax, const char *s)
|
||||
overlap_guard--;
|
||||
}
|
||||
|
||||
ASSERT(false, "dest buffer has no enough space.");
|
||||
pr_err("%s: dest buffer has no enough space.", __func__);
|
||||
|
||||
/*
|
||||
* to avoid a string that is not
|
||||
|
||||
Reference in New Issue
Block a user