[PATCH] lib: framework: don't check for long string if src is NULL
Colin King
colin.king at canonical.com
Mon May 20 10:06:46 UTC 2013
From: Colin Ian King <colin.king at canonical.com>
Commit 8f551a8719f0b0261076f5d873f2fa709008d325 introduced a new
bug. We must no check for long strings if src is NULL.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_framework.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index adb46c8..ff1e3b3 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -291,16 +291,15 @@ static void fwts_framework_show_tests(fwts_framework *fw, bool full)
*/
static void fwts_framework_strtrunc(char *dest, const char *src, size_t max)
{
- if (src)
+ if (src) {
strncpy(dest, src, max);
- else
+ if ((max > 3) && (strlen(src) > max)) {
+ dest[max-1] = 0;
+ dest[max-2] = '.';
+ dest[max-3] = '.';
+ }
+ } else
strncpy(dest, "", max);
-
- if ((strlen(src) > max) && (max > 3)) {
- dest[max-1] = 0;
- dest[max-2] = '.';
- dest[max-3] = '.';
- }
}
/*
--
1.8.1.2
More information about the fwts-devel
mailing list