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);
|
size_t prefixlen = SDL_strlen(replacements[i].prefix);
|
||||||
if (SDL_strncasecmp(name, replacements[i].prefix, prefixlen) == 0) {
|
if (SDL_strncasecmp(name, replacements[i].prefix, prefixlen) == 0) {
|
||||||
size_t replacementlen = SDL_strlen(replacements[i].replacement);
|
size_t replacementlen = SDL_strlen(replacements[i].replacement);
|
||||||
|
if (replacementlen <= prefixlen) {
|
||||||
SDL_memcpy(name, replacements[i].replacement, replacementlen);
|
SDL_memcpy(name, replacements[i].replacement, replacementlen);
|
||||||
SDL_memmove(name+replacementlen, name+prefixlen, (len-prefixlen+1));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1768,11 +1773,9 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
|
||||||
int matchlen = PrefixMatch(name, &name[i]);
|
int matchlen = PrefixMatch(name, &name[i]);
|
||||||
if (matchlen > 0 && name[matchlen-1] == ' ') {
|
if (matchlen > 0 && name[matchlen-1] == ' ') {
|
||||||
SDL_memmove(name, name+matchlen, len-matchlen+1);
|
SDL_memmove(name, name+matchlen, len-matchlen+1);
|
||||||
len -= matchlen;
|
|
||||||
break;
|
break;
|
||||||
} else if (matchlen > 0 && name[matchlen] == ' ') {
|
} else if (matchlen > 0 && name[matchlen] == ' ') {
|
||||||
SDL_memmove(name, name+matchlen+1, len-matchlen);
|
SDL_memmove(name, name+matchlen+1, len-matchlen);
|
||||||
len -= (matchlen + 1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue