diff mbox

[4/4] lib/igt_debugfs: Only use valid values in igt_crc_to_str()

Message ID 20170605132840.9125-5-liviu.dudau@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Liviu Dudau June 5, 2017, 1:28 p.m. UTC
From: Brian Starkey <brian.starkey@arm.com>

Not all elements in the crc array may be valid, so only use the valid
ones to generate the string.

Signed-off-by: Brian Starkey <brian.starkey@arm.com>
---
 lib/igt_debugfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Arkadiusz Hiler June 6, 2017, 11:06 a.m. UTC | #1
On Mon, Jun 05, 2017 at 02:28:40PM +0100, Liviu Dudau wrote:
> From: Brian Starkey <brian.starkey@arm.com>
> 
> Not all elements in the crc array may be valid, so only use the valid
> ones to generate the string.
> 
> Signed-off-by: Brian Starkey <brian.starkey@arm.com>
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>

> ---
>  lib/igt_debugfs.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
> index f5ed3daf..80f25c61 100644
> --- a/lib/igt_debugfs.c
> +++ b/lib/igt_debugfs.c
> @@ -312,10 +312,11 @@ void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b)
>   */
>  char *igt_crc_to_string(igt_crc_t *crc)
>  {
> -	char buf[128];
> +	int i;
> +	char buf[128] = { 0 };
>  
> -	sprintf(buf, "%08x %08x %08x %08x %08x", crc->crc[0],
> -		crc->crc[1], crc->crc[2], crc->crc[3], crc->crc[4]);
> +	for (i = 0; i < crc->n_words; i++)
> +		sprintf(buf + strlen(buf), "%08x ", crc->crc[i]);

Although it is worth noting that this will result in an excessive space
at the end and the format will change.

This should be fine for the few debug messages from the tests...
but may brake something that parses output of intel_display_crc tool.
diff mbox

Patch

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index f5ed3daf..80f25c61 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -312,10 +312,11 @@  void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b)
  */
 char *igt_crc_to_string(igt_crc_t *crc)
 {
-	char buf[128];
+	int i;
+	char buf[128] = { 0 };
 
-	sprintf(buf, "%08x %08x %08x %08x %08x", crc->crc[0],
-		crc->crc[1], crc->crc[2], crc->crc[3], crc->crc[4]);
+	for (i = 0; i < crc->n_words; i++)
+		sprintf(buf + strlen(buf), "%08x ", crc->crc[i]);
 
 	return strdup(buf);
 }