Pass the destination buffer size minus one to strncpy

Copying the last byte was pointless, since the next line overwrites it,
and resulted in a compiler warning:

../src/intel/common/intel_measure.c: In function 'intel_measure_init':
../src/intel/common/intel_measure.c:68:7: warning: 'strncpy' specified bound 1024 equals destination size [-Wstringop-truncation]
   68 |       strncpy(env_copy, env, 1024);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

This allows dropping -Wno-error=stringop-truncation from the
debian-x86_64-asan & debian-{arm64,x86_64}-ubsan CI jobs.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39429>
This commit is contained in:
Michel Dänzer 2026-01-21 10:00:20 +01:00 committed by Michel Dänzer
parent ed180a1c20
commit a74ffd6900
3 changed files with 2 additions and 5 deletions

View file

@ -60,7 +60,6 @@ debian-x86_64-asan:
VULKAN_DRIVERS: "swrast,amd,intel"
GALLIUM_DRIVERS: "llvmpipe,softpipe,zink,r300"
C_ARGS: >
-Wno-error=stringop-truncation
-Wno-error=deprecated-declarations
EXTRA_OPTION: >
-D intel-elk=false
@ -149,7 +148,6 @@ debian-x86_64-ubsan:
variables:
C_ARGS: >
-Wno-error=stringop-overflow
-Wno-error=stringop-truncation
-Wno-error=deprecated-declarations
CPP_ARGS: >
-Wno-error=array-bounds
@ -533,7 +531,6 @@ debian-arm64-ubsan:
C_ARGS: >
-Wno-error=array-bounds
-Wno-error=stringop-overflow
-Wno-error=stringop-truncation
-Wno-error=deprecated-declarations
CPP_ARGS: >
-Wno-error=array-bounds

View file

@ -383,7 +383,7 @@ hud_pipe_query_install(struct hud_batch_query_context **pbq,
if (!gr)
return;
strncpy(gr->name, name, sizeof(gr->name));
strncpy(gr->name, name, sizeof(gr->name) - 1);
gr->name[sizeof(gr->name) - 1] = '\0';
gr->query_data = CALLOC_STRUCT(query_info);
if (!gr->query_data)

View file

@ -65,7 +65,7 @@ intel_measure_init(struct intel_measure_device *device)
return;
char env_copy[1024];
strncpy(env_copy, env, 1024);
strncpy(env_copy, env, 1023);
env_copy[1023] = '\0';
config.file = stderr;