[Intel-gfx] [PATCH i-g-t 3/8] tools/intel_vbt_decode: use %.*s instead of duplicating a string

Jani Nikula jani.nikula at intel.com
Thu Oct 19 15:22:54 UTC 2017


child->device_id may not be terminated, but we can use %.*s format
specifier to define the max length to print. No need to make a copy.

Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 tools/intel_vbt_decode.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/tools/intel_vbt_decode.c b/tools/intel_vbt_decode.c
index 4865f0bab25f..0f7e2dafc762 100644
--- a/tools/intel_vbt_decode.c
+++ b/tools/intel_vbt_decode.c
@@ -388,19 +388,15 @@ static void dump_child_device(struct context *context,
 			      const struct child_device_config *child)
 {
 	const struct child_device_config *efp = child;
-	char child_id[11];
 
 	if (!child->device_type)
 		return;
 
 	if (context->bdb->version < 152) {
-		strncpy(child_id, (const char *)child->device_id, 10);
-		child_id[10] = 0;
-
 		printf("\tChild device info:\n");
 		printf("\t\tDevice type: %04x (%s)\n", child->device_type,
 		       child_device_type(child->device_type));
-		printf("\t\tSignature: %s\n", child_id);
+		printf("\t\tSignature: %.*s\n", (int)sizeof(child->device_id), child->device_id);
 		printf("\t\tAIM offset: %d\n", child->addin_offset);
 		printf("\t\tDVO port: 0x%02x\n", child->dvo_port);
 	} else { /* 152+ have EFP blocks here */
-- 
2.11.0



More information about the Intel-gfx mailing list