Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error in latest master #70

Open
buelowp opened this issue Aug 19, 2022 · 9 comments
Open

Build error in latest master #70

buelowp opened this issue Aug 19, 2022 · 9 comments

Comments

@buelowp
Copy link

buelowp commented Aug 19, 2022

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];
 }
@Infinoid
Copy link

I just ran into the same problem and found this ticket by googling. Thanks for creating it.

@buelowp, I think your patch is close, but it will print a lot of error messages. snprintf returns the number of bytes written, so the error message will happen whenever a nonzero number of bytes were written. (Which is probably usually true.)

@Infinoid
Copy link

I modified my copy slightly to check if ret > 4.

@ChrisJMacdonald
Copy link

Cheers! Thanks for the patch

@DariusKaz
Copy link

Thnx for the fix!

@martinSusz
Copy link

What do you think about this alternative solution: martinSusz@1e6322c ?

@brrrglund
Copy link

I'm a noob in the blind trying to solve this issue. How do I actually run this patch?

I've tried entering the rkdeveloptool folder and pasting the whole thing in the terminal but get a "zsh: parse error near `}'". Am I on the right track at all?

@Pinjontall94
Copy link

Would also love to know how to apply this

@ChrisJMacdonald
Copy link

So the above solution is not a command to run, but is showing the Git Diff between the original main.cpp file, and the patched version (More on reading these diffs here: https://www.atlassian.com/git/tutorials/saving-changes/git-diff)

Essentially, you want to open the main.cpp file, find the lines referenced above, remove the lines that have -- prefix, and add in the new lines that have the ++prefix.
Then save and try run 👍

@buelowp
Copy link
Author

buelowp commented Feb 6, 2024

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)) > 4) {
+            perror("snprintf");
+        }
        return buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3];
 }

Copy this into a file called snprintf.patch and save it to the same folder as main.cpp. Then, run patch -p0 < snprintf.patch. I can't really get into the details of how to use patch or patch for Windows here, there are a LOT of google results to help with that. However, that short workflow will apply the patch.

Then you must build it, and once built, you can use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants