summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2014-09-15 23:07:34 -0400
committerMichael Sevakis <jethead71@rockbox.org>2014-09-15 23:07:34 -0400
commitc1bbaf4050c25f323ab6c37492608de8ecb66968 (patch)
treefcf77a9a4ee10f0d3c9d161aed0af77ec91c17dd
parent77bfff58ec440fc1d666fdd398cb9efbf1a1c287 (diff)
downloadrockbox-c1bbaf4.tar.gz
rockbox-c1bbaf4.tar.bz2
rockbox-c1bbaf4.zip
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
-rw-r--r--firmware/common/pathfuncs.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c
index 4410275adb..1ee5fe9886 100644
--- a/firmware/common/pathfuncs.c
+++ b/firmware/common/pathfuncs.c
@@ -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)
{
+ /* NOTE: this won't currently treat DEL (0x7f) as non-printable */
+ const unsigned char *p = name;
int c;
- while ((c = *name) <= ' ' && c)
- ++name;
- const char *first = name;
- const char *last = name;
+ while ((c = *p) <= ' ' && c)
+ ++p;
+
+ const unsigned char *first = p;
+ const unsigned char *last = p;
while (1)
{
@@ -217,9 +220,9 @@ size_t path_trim_whitespace(const char *name, const char **nameptr)
return last - first;
}
- while ((c = *++name) > ' ');
- last = name;
- while (c == ' ') c = *++name;
+ while ((c = *++p) > ' ');
+ last = p;
+ while (c == ' ') c = *++p;
}
}