-
Notifications
You must be signed in to change notification settings - Fork 2
Fix freeze bug in FlashKeyValue.ino #32
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
Conversation
The old version contained code like this: Serial.println("FlashIAP block device size: " + blockDevice.size()); This adds a large number (the block device size) to the address of the string literal before the + sign. It becomes an illegal address, which triggers a BusFault exception, and the sketch freezes after printing "FlashIAPBlockDevice + TDBStore Test."
Memory usage change @ 7c3004b
Click for full report table
Click for full report CSV
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Explanation of ChatGPT regarding the issue @alrvid 's solved: Based on the provided code snippet, it appears that there is a bug in the line: Serial.println("FlashIAP block device size: " + blockDevice.size()); The bug lies in the concatenation operation between the string literal ( To fix this issue, you need to convert the numerical value to a string before concatenating it with the string literal. One way to achieve this is by using the Serial.println("FlashIAP block device size: " + String(blockDevice.size())); By wrapping In this PR, |
@aliphys Likely ChatGPT is not correct here. The problem is with the string literal which is not of type Serial.println(String("FlashIAP block device size: ") + blockDevice.size()); This should work because the String class has an operator overload for + with numeric values. See: |
The answer from ChatGPT is incorrect for two reasons:
Both: Serial.println("FlashIAP block device size: " + String((uint32_t) blockDevice.size())); and: Serial.println(String("FlashIAP block device size: ") + (uint32_t) blockDevice.size()); are possible, but slightly suboptimal workarounds compared to the separate print() plus println() solution, because they force the uint64_t into a uint32_t. In the first case, the compiler performs an implicit conversion of the string literal to String because there's a String to the right and there's a conversion operator defined from const char * to String. The compiler then uses the + operator overload of the implicitly converted result together with the second string that results from passing a uint32_t to the String constructor. In the second case, the compiler simply uses the + operator overload of the String to the left together with the uint32_t. The reason why Serial.println(blockDevice.size()) in the pull request works is that there's an overloaded version of println() that takes an unsigned long long. Thus, there is no loss of precision compared to the other two solutions. |
The old version contained code like this: Serial.println("FlashIAP block device size: " + blockDevice.size());
This adds a large number (the block device size) to the address of the string literal before the + sign. It becomes an illegal address, which triggers a BusFault exception, and the sketch freezes after printing "FlashIAPBlockDevice + TDBStore Test."