mirror of https://github.com/encounter/SDL.git
Update length after shortening string (thanks mayraud705!)
Closes https://github.com/libsdl-org/SDL/pull/4698
This commit is contained in:
parent
77acd44f28
commit
9706feacae
|
@ -1757,8 +1757,13 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
|
|||
size_t prefixlen = SDL_strlen(replacements[i].prefix);
|
||||
if (SDL_strncasecmp(name, replacements[i].prefix, prefixlen) == 0) {
|
||||
size_t replacementlen = SDL_strlen(replacements[i].replacement);
|
||||
SDL_memcpy(name, replacements[i].replacement, replacementlen);
|
||||
SDL_memmove(name+replacementlen, name+prefixlen, (len-prefixlen+1));
|
||||
if (replacementlen <= prefixlen) {
|
||||
SDL_memcpy(name, replacements[i].replacement, replacementlen);
|
||||
SDL_memmove(name+replacementlen, name+prefixlen, (len-prefixlen)+1);
|
||||
len -= (prefixlen - replacementlen);
|
||||
} else {
|
||||
/* FIXME: Need to handle the expand case by reallocating the string */
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1768,11 +1773,9 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
|
|||
int matchlen = PrefixMatch(name, &name[i]);
|
||||
if (matchlen > 0 && name[matchlen-1] == ' ') {
|
||||
SDL_memmove(name, name+matchlen, len-matchlen+1);
|
||||
len -= matchlen;
|
||||
break;
|
||||
} else if (matchlen > 0 && name[matchlen] == ' ') {
|
||||
SDL_memmove(name, name+matchlen+1, len-matchlen);
|
||||
len -= (matchlen + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue