SuperTux / supertux

SuperTux source code
https://supertux.org
GNU General Public License v3.0
2.5k stars 479 forks source link

Fix windows crash viewer #2987

Open MatusGuy opened 3 months ago

NickerAban commented 3 months ago

finally!

MatusGuy commented 3 months ago

wtfreaky

MatusGuy commented 1 month ago

@tobbi How can I ignore the cppcheck errors?

tobbi commented 1 month ago

Can you not simply fix them? Add a check for the path being empty?

MatusGuy commented 1 month ago

I still need to pass &path[0] which shouldn't cause issues anyway because I already reserve MAX_PATH bytes

tobbi commented 1 month ago

I think it can still be empty

MatusGuy commented 1 month ago

The contents of the string are empty but the size isn't. path[0] would probably just give a null character

tobbi commented 1 month ago

14:20:39] Tobbi: If I have an std::string and call reserve on it, can &path[0] still be out of bounds if the string itself is empty [14:32:43] PJBoy: yeah [14:32:58] PJBoy: well [14:33:05] PJBoy: you can take the address just fine [14:33:30] PJBoy: and if you make the string non-empty without exceeding the capacity you reserved, that address will become dereferencable

MatusGuy commented 1 month ago

Alright then how do I check if the string is invalid before passing it into GetModuleFileName (the function that fills the string)?

tobbi commented 1 month ago

Just check the length: https://cplusplus.com/reference/string/string/length/

MatusGuy commented 1 month ago

If GetModuleFileName fills the string then won't checking for the length of the string always reach the same result?

tobbi commented 1 month ago

Just check whether it's greater than 0, to silence the warning.