Compiler error (gcc-16.1.1) about vcgencmd with strncat
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- c
- Domain
- cli, embedded-iot
Research direction
Start in vcgencmd/vcgencmd.c around the gencmd function and reproduce the gcc-16.1.1 build failure with warnings treated as errors. Check the suggested bounded-copy change against the existing result buffer behavior. Done means the build no longer reports the strncat truncation warning while the command output remains safely terminated.
Written by the indexing model from the issue text.
Description
When using your code, but compiled with other flags, one gets the error:
In function 'gencmd',
inlined from 'rpi_temp' at p/rpi_temp.c:156:15:
p/rpi_temp.c:124:5: error: 'strncat' output may be truncated copying 4096 bytes from a string of length 4099 [-Werror=stringop-truncation]
124 | strncat(result, (const char *)(p+6), result_len-1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
line 113 in vcgencmd.c is the problem, some AI suggest something safer like
diff --git a/vcgencmd/vcgencmd.c b/vcgencmd/vcgencmd.c
index 63faf2e..bc5725c 100644
--- a/vcgencmd/vcgencmd.c
+++ b/vcgencmd/vcgencmd.c
@@ -109,8 +109,8 @@ static unsigned gencmd(int file_desc, const char *command, char *result, int res
p[0] = i*sizeof *p; // actual size
mbox_property(file_desc, p);
- result[0] = 0;
- strncat(result, (const char *)(p+6), result_len);
+ // Safely copies up to result_len - 1 characters and guarantees a \0 at the end
+ snprintf(result, result_len, "%s", (const char *)(p+6));
return p[5];
}
- Dominant language
- C
- Stars
- 346
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from raspberrypi/utils
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
raspberrypi/utils#147 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
raspberrypi/utils#159 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
raspberrypi/utils#158 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
raspberrypi/utils#137 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
raspberrypi/utils#133 · 1 comment ·
All issues in raspberrypi/utils
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100