TheAssemblyArmada / Vanilla-Conquer

Vanilla Conquer provides clean, cross-platform builds of the C&C Remastered Collection and the standalone legacy games.
Other
330 stars 51 forks source link

Replace strlen upper bound with checks for '\0' #1018

Closed giulianobelinassi closed 1 week ago

giulianobelinassi commented 1 week ago

Strings in C are always terminated by the '\0' character. We can explore this to avoid sweeping through the string twice.

Constructs like for (i = 0; i < strlen(str); i++) are even worse than this, as it will call strlen for each character of the string, which is O(n ²) instead of O(n), where n = size of string. Replace those cases as well.