alliedmodders / metamod-source

Metamod:Source - C++ Plugin Environment and Detour Library for the Source Engine
http://www.metamodsource.net/
Other
374 stars 83 forks source link

C6293: Ill-defined for-loop in UTIL_TrimRight #118

Closed sapphonie closed 9 months ago

sapphonie commented 11 months ago

https://github.com/alliedmodders/metamod-source/blob/4401a94aa620b1db756840a7b85536846561d06f/core/metamod_util.cpp#L93-L111

Discovered while poking around CS2 mms stuff

dvander commented 11 months ago

Boy is that an old one. Should be something like this, if you want to attempt a fix:

if (!buffer)
    return;
size_t len = strlen(buffer);
while (len) {
    if (!isspace((unsigned char)buffer[len - 1]))
        break;
    len--;
}
buffer[len] = '\0';

(or convert the code calling this to use std::string which is way nicer to work with)

sapphonie commented 9 months ago

Fixed as of #121