Skip to content

Commit

Permalink
drm/i915/selftest: Ensure string fits within name[]
Browse files Browse the repository at this point in the history
Shrink the strncpy bounds to ensure the NUL-terminator can fit within
the embedded array:

In file included from drivers/gpu/drm/i915/gem/i915_gem_context.c:2475:
drivers/gpu/drm/i915/gem/selftests/mock_context.c: In function ‘mock_context’:
drivers/gpu/drm/i915/gem/selftests/mock_context.c:40:3: error: ‘strncpy’ specified bound 24 equals destination size [-Werror=stringop-truncation]
   40 |   strncpy(ctx->name, name, sizeof(ctx->name));

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200203181625.589118-1-chris@chris-wilson.co.uk
  • Loading branch information
Chris Wilson committed Feb 4, 2020
1 parent bb5e439 commit 0a3b94a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/gem/selftests/mock_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mock_context(struct drm_i915_private *i915,
if (name) {
struct i915_ppgtt *ppgtt;

strncpy(ctx->name, name, sizeof(ctx->name));
strncpy(ctx->name, name, sizeof(ctx->name) - 1);

ppgtt = mock_ppgtt(i915, name);
if (!ppgtt)
Expand Down

0 comments on commit 0a3b94a

Please sign in to comment.