[Intel-gfx] [PATCH 3/9] external/drm: Use snprintf instead of sprintf

Praveen Paneri praveen.paneri at intel.com
Thu Mar 5 21:45:08 PST 2015


We must have upper bound on what we are going to write into a fixed
size buffer.

Signed-off-by: Praveen Paneri <praveen.paneri at intel.com>
---
 intel/intel_decode.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/intel/intel_decode.c b/intel/intel_decode.c
index 61239dd..2667a7c 100644
--- a/intel/intel_decode.c
+++ b/intel/intel_decode.c
@@ -762,7 +762,7 @@ static void i915_get_instruction_src0(uint32_t *data, int i, char *srcname)
 	char swizzle[100];
 
 	i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
-	sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
+	snprintf(swizzle, sizeof(swizzle), ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
 		swizzle_w);
 	if (strcmp(swizzle, ".xyzw") != 0)
 		strcat(srcname, swizzle);
@@ -780,7 +780,7 @@ static void i915_get_instruction_src1(uint32_t *data, int i, char *srcname)
 	char swizzle[100];
 
 	i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
-	sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
+	snprintf(swizzle, sizeof(swizzle), ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
 		swizzle_w);
 	if (strcmp(swizzle, ".xyzw") != 0)
 		strcat(srcname, swizzle);
@@ -797,7 +797,7 @@ static void i915_get_instruction_src2(uint32_t *data, int i, char *srcname)
 	char swizzle[100];
 
 	i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
-	sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
+	snprintf(swizzle, sizeof(swizzle), ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
 		swizzle_w);
 	if (strcmp(swizzle, ".xyzw") != 0)
 		strcat(srcname, swizzle);
@@ -926,7 +926,7 @@ i915_decode_dcl(struct drm_intel_decode *ctx, int i, char *instr_prefix)
 
 	switch ((d0 >> 19) & 0x3) {
 	case 1:
-		sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
+		snprintf(dcl_mask, sizeof(dcl_mask), ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
 		if (strcmp(dcl_mask, ".") == 0)
 			fprintf(out, "bad (empty) dcl mask\n");
 
-- 
1.9.1



More information about the Intel-gfx mailing list