rkdeveloptool
rkdeveloptool copied to clipboard
Build error in latest master
Later versions of GCC have started to generate the warning
main.cpp:1493:43: error: ‘%s’ directive output may be truncated writing up to 557 bytes into a region of size 5 [-Werror=format-truncation=]
1493 | snprintf(buffer, sizeof(buffer), "%s", chip);
| ^~
and because -Wall and -Werror are used, this causes the build to fail. I've attached the patch I used, but there may be a better solution.
diff --git a/main.cpp b/main.cpp
index 72bd94b..ec5257b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1489,8 +1489,12 @@ static bool saveEntry(FILE* outFile, char* path, rk_entry_type type,
static inline uint32_t convertChipType(const char* chip) {
char buffer[5];
+ int ret = 0;
+
memset(buffer, 0, sizeof(buffer));
- snprintf(buffer, sizeof(buffer), "%s", chip);
+ if ((ret = snprintf(buffer, sizeof(buffer), "%s", chip))) {
+ perror("snprintf");
+ }
return buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3];
}