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];
}
When using your code, but compiled with other flags, one gets the error:
line 113 in vcgencmd.c is the problem, some AI suggest something safer like