Skip to contentSkip to conversation

i915: snprintf returns large values

PATCH Applied Dan Carpenter 2 participants 2 messages Sep 8, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i915: snprintf returns large values

snprintf() returns the number of bytes which would have been used if there was enough space. It can be larger than the size of the buffer. Obviously in this case the buffer is large enough but everyone just copy and pastes this code so it's better to limit it and set a good example.

drivers/gpu/drm/i915/i915_debugfs.c +3 -0
index 5e43d70..1cb29ec 100644
@@ -741,6 +741,9 @@ i915_wedged_read(struct file *filp,
 		       "wedged :  %d\n",
 		       atomic_read(&dev_priv->mm.wedged));
 
+	if (len > sizeof (buf))
+		len = sizeof (buf);
+
 	return simple_read_from_buffer(ubuf, max, ppos, buf, len);
 }
 
Applied
#1 lore raw
Quoted 5 lines · Dan Carpenter

snprintf() returns the number of bytes which would have been used if there was enough space. It can be larger than the size of the buffer. Obviously in this case the buffer is large enough but everyone just copy and pastes this code so it's better to limit it and set a good example.

Applied to drm-intel-next as it is just a pedagogical fix. Thanks,
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre