[llvm-commits] CVS: llvm/lib/System/Win32/Path.inc
Jeff Cohen
jeffc at jolt-lang.org
Thu Jan 13 20:09:50 PST 2005
Changes in directory llvm/lib/System/Win32:
Path.inc updated: 1.27 -> 1.28
---
Log message:
Fix and improve win32 path validation.
---
Diffs of the changes: (+22 -10)
Index: llvm/lib/System/Win32/Path.inc
diff -u llvm/lib/System/Win32/Path.inc:1.27 llvm/lib/System/Win32/Path.inc:1.28
--- llvm/lib/System/Win32/Path.inc:1.27 Fri Dec 31 13:03:31 2004
+++ llvm/lib/System/Win32/Path.inc Thu Jan 13 22:09:39 2005
@@ -55,17 +55,29 @@
!= std::string::npos)
return false;
- // A file or directory name may not end in a period.
- if (path[len-1] == '.')
- return false;
- if (len >= 2 && path[len-2] == '.' && path[len-1] == '/')
- return false;
+ // Check each component for legality.
+ for (pos = 0; pos < len; ++pos) {
+ // A component may not end in a space.
+ if (path[pos] == ' ') {
+ if (path[pos+1] == '/' || path[pos+1] == '\0')
+ return false;
+ }
- // A file or directory name may not end in a space.
- if (path[len-1] == ' ')
- return false;
- if (len >= 2 && path[len-2] == ' ' && path[len-1] == '/')
- return false;
+ // A component may not end in a period.
+ if (path[pos] == '.') {
+ if (path[pos+1] == '/' || path[pos+1] == '\0') {
+ // Unless it is the pseudo-directory "."...
+ if (pos == 0 || path[pos-1] == '/' || path[pos-1] == ':')
+ return true;
+ // or "..".
+ if (pos > 0 && path[pos-1] == '.') {
+ if (pos == 1 || path[pos-2] == '/' || path[pos-2] == ':')
+ return true;
+ }
+ return false;
+ }
+ }
+ }
return true;
}
More information about the llvm-commits
mailing list