Problems with (external) library using SDFat

If the length of the [[ String arduinoStringValue ]] exceeds a certain value (69?) the added part " new"
[[ arduinoStringValue += " new"; ]] will be written to the "test_file.txt" in a separate line.

might be that there is a buffer overflow?!??
Looks like the default line buffer is set to 80chars. Its defined in SdConfigFile.h:
Code:
// If lines containing parameter values in the
// config file are longer than 40 characters, the
// length of the buffer can be changed here
#ifndef SDCONFIG_BUFFER_LENGTH
#define SDCONFIG_BUFFER_LENGTH 80//(40)
#endif /* SDCONFIG_BUFFER_LENGTH */

You can try to change the buffer length - should resolve the issue. Fingers crossed
 
Last edited:
I stumbled across an issue which I cannot explain:
- compile and load "ReadWrite_ConfigFile_MTP_littleFS"
- toggle the Teensy on & off for a couple of times (>10)

then the "test_file.txt" will look like the attached one.
looks like if a write to the SD-Card fails if the length of the
Code:
String arduinoStringValue
exceeds a certain value (~69) when adding the text " new" to it
Code:
  arduinoStringValue += " new";

Maybe it generates a buffer overflow??? (just guessing) or the file is not closed correctly?

If i jut put in a loop in the code
Code:
for (int i = 1; i<10 ;i++)
{
    arduinoStringValue += " new";
    configFile.set("arduinoString", arduinoStringValue);
    configFile.get("arduinoString", arduinoStringValue);
    Serial.printf("Loop #: %i\n",i);
    outputParameterValues();
}
everything seems to be fine.

Cheers,
Tom
 

Attachments

  • test_file.txt
    818 bytes · Views: 6
Looks like the default line buffer is set to 80chars. Its defined in SdConfigFile.h:
Code:
// If lines containing parameter values in the
// config file are longer than 40 characters, the
// length of the buffer can be changed here
#ifndef SDCONFIG_BUFFER_LENGTH
#define SDCONFIG_BUFFER_LENGTH 80//(40)
#endif /* SDCONFIG_BUFFER_LENGTH */

You can try to change the buffer length - should resolve the issue. Fingers crossed

Sorry, just saw your message...
Will change the buffer length & try again.
 
I'm finally back. Looks like a lot of things are happening. I was going to mention the buffer size setting in the instructions but forgot. Love getting oldo_O I'll add those in today. Still checking out the "FILE_WRITE_BEGIN" vs. "FILE_WRITE" question. It looks like it's top down writing then close file. The author mentions this in setion 3 of the readme file. He also says that value that are changed are appended to the end of the file. So I think that using "FILE_WRITE_BEGIN"might not be needed at all in the code. I'll update and test...

EDIT: Changes made,tested ok. Not using "FILE_WRITE_BEGIN". Updated repo...
 
Last edited:
Back
Top