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:
Yan, Like
2018-03-12 16:07:53 +08:00
committed by Jack Ren
parent cc2256d3f6
commit 7e4b4c2546
4 changed files with 42 additions and 18 deletions

View File

@@ -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