Closed NQNStudios closed 2 months ago
That's here, for conversational reference:
Also, is it reading chunks of 128 characters at a time from a command? Why not just read 1 at a time until it reaches the end rather than request more than is known to be there?
I don't really know. I assume that requesting 128 characters when there are only 30 characters is fine though.
So, what would make it safe? Setting the index after the end of the buffer to the zero/null terminator? Constructing a std::string before calling += ?
I was thinking using std::append
instead of +=
, as there's a form of that which takes a count. But then I looked at the fgets
documentation and realized that it actually reads only 127 characters and adds a null terminator, so +=
seems to be safe after all.
This isn't really related, but I just realized that the
filename += buffer
line might be unsafe. I'm not sure if it correctly accounts for the fact that the buffer is known to be 128 characters.