summaryrefslogtreecommitdiff
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-c1bbaf4050c25f323ab6c37492608de8ecb66968.tar.gz
rockbox-c1bbaf4050c25f323ab6c37492608de8ecb66968.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)
202 */ 202 */
203size_t path_trim_whitespace(const char *name, const char **nameptr) 203size_t path_trim_whitespace(const char *name, const char **nameptr)
204{ 204{
205 /* NOTE: this won't currently treat DEL (0x7f) as non-printable */
206 const unsigned char *p = name;
205 int c; 207 int c;
206 while ((c = *name) <= ' ' && c)
207 ++name;
208 208
209 const char *first = name; 209 while ((c = *p) <= ' ' && c)
210 const char *last = name; 210 ++p;
211
212 const unsigned char *first = p;
213 const unsigned char *last = p;
211 214
212 while (1) 215 while (1)
213 { 216 {
@@ -217,9 +220,9 @@ size_t path_trim_whitespace(const char *name, const char **nameptr)
217 return last - first; 220 return last - first;
218 } 221 }
219 222
220 while ((c = *++name) > ' '); 223 while ((c = *++p) > ' ');
221 last = name; 224 last = p;
222 while (c == ' ') c = *++name; 225 while (c == ' ') c = *++p;
223 } 226 }
224} 227}
225 228