forked from len0rd/rockbox
Fix path_trim_whitespace() sign extension.
It should have been implemented as interpreting chars as unsigned so that code points >= 0x80 would not get sign-extended and seen as negative values. Fixes FS#12995 - path_trim_whitespace() assumes unsigned char Change-Id: I514e369681e00151588585311a0b6c66b9b5200c
This commit is contained in:
parent
77bfff58ec
commit
c1bbaf4050
1 changed files with 10 additions and 7 deletions
|
|
@ -202,12 +202,15 @@ int path_strip_drive(const char *name, const char **nameptr, bool greedy)
|
||||||
*/
|
*/
|
||||||
size_t path_trim_whitespace(const char *name, const char **nameptr)
|
size_t path_trim_whitespace(const char *name, const char **nameptr)
|
||||||
{
|
{
|
||||||
|
/* NOTE: this won't currently treat DEL (0x7f) as non-printable */
|
||||||
|
const unsigned char *p = name;
|
||||||
int c;
|
int c;
|
||||||
while ((c = *name) <= ' ' && c)
|
|
||||||
++name;
|
|
||||||
|
|
||||||
const char *first = name;
|
while ((c = *p) <= ' ' && c)
|
||||||
const char *last = name;
|
++p;
|
||||||
|
|
||||||
|
const unsigned char *first = p;
|
||||||
|
const unsigned char *last = p;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
@ -217,9 +220,9 @@ size_t path_trim_whitespace(const char *name, const char **nameptr)
|
||||||
return last - first;
|
return last - first;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c = *++name) > ' ');
|
while ((c = *++p) > ' ');
|
||||||
last = name;
|
last = p;
|
||||||
while (c == ' ') c = *++name;
|
while (c == ' ') c = *++p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue