[PATCH] lib: framework: don't check for long string if src is NULL

IvanHu ivan.hu at canonical.com
Wed May 22 02:27:43 UTC 2013


On 05/20/2013 06:06 PM, Colin King wrote:
> 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] = '.';
> -	}
>   }
>
>   /*
>

Acked-by: Ivan Hu <ivan.hu at canonical.com>



More information about the fwts-devel mailing list