mesa/main: do not copy the exact size of the string
authorCorentin Noël <corentin.noel@collabora.com>
Thu, 15 Sep 2022 12:49:22 +0000 (14:49 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 30 Sep 2022 12:38:11 +0000 (12:38 +0000)
This fixes a compiler warning with stringop-truncation:
```
error: 'strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation]
  286 |    strncpy(s, msg, MAX_DEBUG_MESSAGE_LENGTH);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

Signed-off-by: Corentin Noël <corentin.noel@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18613>

src/mesa/main/errors.c

index 10fe3fc..938b6e7 100644 (file)
@@ -283,7 +283,7 @@ _mesa_gl_debug(struct gl_context *ctx,
 
    /* limit the message to fit within KHR_debug buffers */
    char s[MAX_DEBUG_MESSAGE_LENGTH];
-   strncpy(s, msg, MAX_DEBUG_MESSAGE_LENGTH);
+   strncpy(s, msg, MAX_DEBUG_MESSAGE_LENGTH - 1);
    s[MAX_DEBUG_MESSAGE_LENGTH - 1] = '\0';
    len = MAX_DEBUG_MESSAGE_LENGTH - 1;
    _mesa_log_msg(ctx, source, type, *id, severity, len, s);