you basically write in random location and overwrite other stuff . From there on you are toast
I don’t know why you need to bring the file in memory since the weird stuff you do afterwards is just on checking one byte at a given position - so you could do the parsing while reading the file in SPIFFS
We would recommend not to use the String class in general and remember your SRAM is probably not huge
you should allocate enough space for the longest string that you will use.
IMHO it would also be better to allocate that as a global variable or as a static local variable so it won't continually be created and abandoned.
Also, there is probably no need to create the whole message as a single string if it just for the purpose of sending it somewhere. As far as the recipient is concerned there is no difference between
As such it’s just on the stack so costs nothing to create and nothing to delete. Any reference to part of this buffer will just be an offset relative to the stack pointer, it’s done at compile time. If the file parsing is done only once it’s probably better that way (well the correct way) so as to not lock scarce SRAM for something that is essentially temporary.
But as said above, OP can probably do without a buffer
Well the compiler does not report on stack or heap usage - can't predict recursive calls or dynamic memory allocation if you use that.. so I still think it's a good idea - if you don't need something for the long run to not lock the memory and there is no performance penalty attached here
Now if you have to often read the file and need the buffer then it's q different story as a statically allocated buffer will guarantee the memory is there when you need it